Class PrototypeFactory


  • public class PrototypeFactory
    extends java.lang.Object
    Factory implementation that creates a new instance each time based on a prototype.

    WARNING: from v4.1 onwards Factory instances returned by prototypeFactory(Object) 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
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> Factory<T> prototypeFactory​(T prototype)
      Factory method that performs validation.
      • Methods inherited from class java.lang.Object

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

      • prototypeFactory

        public static <T> Factory<T> prototypeFactory​(T prototype)
        Factory method that performs validation.

        Creates a Factory that will return a clone of the same prototype object each time the factory is used. The prototype will be cloned using one of these techniques (in order):

        • public clone method
        • public copy constructor
        • serialization clone
        Type Parameters:
        T - the type the factory creates
        Parameters:
        prototype - the object to clone each time in the factory
        Returns:
        the prototype factory, or a ConstantFactory.NULL_INSTANCE if the prototype is null
        Throws:
        java.lang.IllegalArgumentException - if the prototype cannot be cloned