Package org.objenesis
Class ObjenesisHelper
- java.lang.Object
-
- org.objenesis.ObjenesisHelper
-
public final class ObjenesisHelper extends java.lang.Object
Use Objenesis in a static way. It is strongly not recommended to use this class.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> ObjectInstantiator<T>
getInstantiatorOf(java.lang.Class<T> clazz)
Will pick the best instantiator for the provided class.static <T extends java.io.Serializable>
ObjectInstantiator<T>getSerializableObjectInstantiatorOf(java.lang.Class<T> clazz)
Same asgetInstantiatorOf(Class)
but providing an instantiator emulating ObjectInputStream.readObject behavior.static <T> T
newInstance(java.lang.Class<T> clazz)
Will create a new object without any constructor being calledstatic <T extends java.io.Serializable>
TnewSerializableInstance(java.lang.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 Detail
-
newInstance
public static <T> T newInstance(java.lang.Class<T> clazz)
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
public static <T extends java.io.Serializable> T newSerializableInstance(java.lang.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)- Type Parameters:
T
- Type instantiated- Parameters:
clazz
- Class to instantiate- Returns:
- New instance of clazz
-
getInstantiatorOf
public static <T> ObjectInstantiator<T> getInstantiatorOf(java.lang.Class<T> clazz)
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 java.io.Serializable> ObjectInstantiator<T> getSerializableObjectInstantiatorOf(java.lang.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:
newSerializableInstance(Class)
-
-