# Class ConstantFactory<T>

java.lang.Object
org.apache.commons.collections4.functors.ConstantFactory<T>

Type Parameters:
  `T` - the type of results supplied by this supplier.

All Implemented Interfaces:
  `Serializable`, `Supplier<T>`, `Factory<T>`

public class ConstantFactory<T> extends Object implements Factory<T>, Serializable
Factory implementation that returns the same constant each time.

No check is made that the object is immutable. In general, only immutable objects should use the constant factory. Mutable objects should use the prototype factory.

Since:
  3.0
See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final Factory`
  `NULL_INSTANCE`
  Returns null each time

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ConstantFactory(T constantToReturn)`
  Constructor that performs no validation.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static <T> Factory<T>`
  `constantFactory(T constantToReturn)`
  Factory method that performs validation.
  `T`
  `create()`
  Always return constant.
  `T`
  `getConstant()`
  Gets the constant.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface org.apache.commons.collections4.Factory

  `get`

- ## Field Details

  - ### NULL_INSTANCE

    public static final Factory NULL_INSTANCE
    Returns null each time

- ## Constructor Details

  - ### ConstantFactory

    public ConstantFactory(T constantToReturn)
    Constructor that performs no validation. Use `constantFactory` if you want that.
    Parameters:
      `constantToReturn` - the constant to return each time

- ## Method Details

  - ### constantFactory

    public static <T> Factory<T> constantFactory(T constantToReturn)
    Factory method that performs validation.
    Type Parameters:
      `T` - the type of the constant
    Parameters:
      `constantToReturn` - the constant object to return each time in the factory
    Returns:
      the `constant` factory.

  - ### create

    public T create()
    Always return constant.
    Specified by:
      `create` in interface `Factory<T>`
    Returns:
      the stored constant value

  - ### getConstant

    public T getConstant()
    Gets the constant.
    Returns:
      the constant
    Since:
      3.1