Class InstantiateTransformer<T>

  • All Implemented Interfaces:
    Transformer<java.lang.Class<? extends T>,​T>

    public class InstantiateTransformer<T>
    extends java.lang.Object
    implements Transformer<java.lang.Class<? extends T>,​T>
    Transformer implementation that creates a new object instance by reflection.

    WARNING: from v4.1 onwards this class will not be serializable anymore in order to prevent potential remote code execution exploits. Please refer to COLLECTIONS-580 for more details.

    Since:
    3.0
    • Constructor Summary

      Constructors 
      Constructor Description
      InstantiateTransformer​(java.lang.Class<?>[] paramTypes, java.lang.Object[] args)
      Constructor that performs no validation.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> Transformer<java.lang.Class<? extends T>,​T> instantiateTransformer()
      Get a typed no-arg instance.
      static <T> Transformer<java.lang.Class<? extends T>,​T> instantiateTransformer​(java.lang.Class<?>[] paramTypes, java.lang.Object[] args)
      Transformer method that performs validation.
      T transform​(java.lang.Class<? extends T> input)
      Transforms the input Class object to a result by instantiation.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • InstantiateTransformer

        public InstantiateTransformer​(java.lang.Class<?>[] paramTypes,
                                      java.lang.Object[] args)
        Constructor that performs no validation. Use instantiateTransformer if you want that.

        Note: from 4.0, the input parameters will be cloned

        Parameters:
        paramTypes - the constructor parameter types
        args - the constructor arguments
    • Method Detail

      • instantiateTransformer

        public static <T> Transformer<java.lang.Class<? extends T>,​T> instantiateTransformer()
        Get a typed no-arg instance.
        Type Parameters:
        T - the type of the objects to be created
        Returns:
        Transformer<Class<? extends T>, T>
      • instantiateTransformer

        public static <T> Transformer<java.lang.Class<? extends T>,​T> instantiateTransformer​(java.lang.Class<?>[] paramTypes,
                                                                                                   java.lang.Object[] args)
        Transformer method that performs validation.
        Type Parameters:
        T - the type of the objects to be created
        Parameters:
        paramTypes - the constructor parameter types
        args - the constructor arguments
        Returns:
        an instantiate transformer
        Throws:
        java.lang.IllegalArgumentException - if paramTypes does not match args
      • transform

        public T transform​(java.lang.Class<? extends T> input)
        Transforms the input Class object to a result by instantiation.
        Specified by:
        transform in interface Transformer<java.lang.Class<? extends T>,​T>
        Parameters:
        input - the input object to transform
        Returns:
        the transformed result