Package org.objenesis

Class ObjenesisHelper


  • public final class ObjenesisHelper
    extends java.lang.Object
    Use Objenesis in a static way. It is strongly not recommended to use this class.
    • Field Detail

      • OBJENESIS_STD

        private static final Objenesis OBJENESIS_STD
      • OBJENESIS_SERIALIZER

        private static final Objenesis OBJENESIS_SERIALIZER
    • Constructor Detail

      • ObjenesisHelper

        private ObjenesisHelper()
    • 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 calling newInstance(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 as getInstantiatorOf(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)