Class 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.
    • 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 interface InstantiatorStrategy
        Type Parameters:
        T - the type we want to instantiate
        Parameters:
        type - Class to instantiate
        Returns:
        The ObjectInstantiator for the class