Package org.objenesis

Class ObjenesisHelper


  • public final class ObjenesisHelper
    extends Object
    Use Objenesis in a static way. It is strongly not recommended to use this class.
    Author:
    Henri Tremblay
    • Method Detail

      • newInstance

        public static <T> T newInstance​(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 Serializable> T newSerializableInstance​(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​(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