Package org.objenesis.strategy
Class SingleInstantiatorStrategy
- java.lang.Object
-
- org.objenesis.strategy.SingleInstantiatorStrategy
-
- All Implemented Interfaces:
InstantiatorStrategy
public class SingleInstantiatorStrategy extends java.lang.Object implements InstantiatorStrategy
Strategy returning only one instantiator type. Useful if you know on which JVM Objenesis will be used and want to specify it explicitly.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.reflect.Constructor<?>
constructor
-
Constructor Summary
Constructors Constructor Description SingleInstantiatorStrategy(java.lang.Class<T> instantiator)
Create a strategy that will return always the same instantiator type.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> ObjectInstantiator<T>
newInstantiatorOf(java.lang.Class<T> type)
Return an instantiator for the wanted type and of the one and only type of instantiator returned by this class.
-
-
-
Constructor Detail
-
SingleInstantiatorStrategy
public SingleInstantiatorStrategy(java.lang.Class<T> instantiator)
Create a strategy that will return always the same instantiator type. We assume this instantiator has one constructor taking the class to instantiate in parameter.- Type Parameters:
T
- the type we want to instantiate- Parameters:
instantiator
- the instantiator type
-
-
Method Detail
-
newInstantiatorOf
public <T> ObjectInstantiator<T> newInstantiatorOf(java.lang.Class<T> type)
Return an instantiator for the wanted type and of the one and only type of instantiator returned by this class.- Specified by:
newInstantiatorOf
in interfaceInstantiatorStrategy
- Type Parameters:
T
- the type we want to instantiate- Parameters:
type
- Class to instantiate- Returns:
- The ObjectInstantiator for the class
-
-