Package org.objenesis
Class ObjenesisHelper
java.lang.Object
org.objenesis.ObjenesisHelper
Use Objenesis in a static way. It is strongly not recommended to use this class.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> ObjectInstantiator
<T> getInstantiatorOf
(Class<T> clazz) Will pick the best instantiator for the provided class.static <T extends Serializable>
ObjectInstantiator<T> getSerializableObjectInstantiatorOf
(Class<T> clazz) Same asgetInstantiatorOf(Class)
but providing an instantiator emulating ObjectInputStream.readObject behavior.static <T> T
newInstance
(Class<T> clazz) Will create a new object without any constructor being calledstatic <T extends Serializable>
TnewSerializableInstance
(Class<T> clazz) Will create an object just like it's done by ObjectInputStream.readObject (the default constructor of the first non serializable class will be called)
-
Method Details
-
newInstance
Will create a new object without any constructor being called- Type Parameters:
T
- Type instantiated- Parameters:
clazz
- Class to instantiate- Returns:
- New instance of clazz
-
newSerializableInstance
Will create an object just like it's done by ObjectInputStream.readObject (the default constructor of the first non serializable class will be called)- Type Parameters:
T
- Type instantiated- Parameters:
clazz
- Class to instantiate- Returns:
- New instance of clazz
-
getInstantiatorOf
Will pick the best instantiator for the provided class. If you need to create a lot of instances from the same class, it is way more efficient to create them from the same ObjectInstantiator than callingnewInstance(Class)
.- Type Parameters:
T
- Type to instantiate- Parameters:
clazz
- Class to instantiate- Returns:
- Instantiator dedicated to the class
-
getSerializableObjectInstantiatorOf
public static <T extends Serializable> ObjectInstantiator<T> getSerializableObjectInstantiatorOf(Class<T> clazz) Same asgetInstantiatorOf(Class)
but providing an instantiator emulating ObjectInputStream.readObject behavior.- Type Parameters:
T
- Type to instantiate- Parameters:
clazz
- Class to instantiate- Returns:
- Instantiator dedicated to the class
- See Also:
-