Class InstanceFactory<T>

  • All Implemented Interfaces:
    Factory<T>, Provider<T>, Lazy<T>, javax.inject.Provider<T>

    public final class InstanceFactory<T>
    extends java.lang.Object
    implements Factory<T>, Lazy<T>
    A Factory implementation that returns a single instance for all invocations of get().

    Note that while this is a Factory implementation, and thus unscoped, each call to get() will always return the same instance. As such, any scoping applied to this factory is redundant and unnecessary. However, using this with DoubleCheck.provider is valid and may be desired for testing or contractual guarantees.

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> Factory<T> create​(T instance)  
      static <T> Factory<T> createNullable​(T instance)  
      T get()
      Return the underlying value, computing the value if necessary.
      • Methods inherited from class java.lang.Object

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

      • create

        public static <T> Factory<T> create​(T instance)
      • createNullable

        public static <T> Factory<T> createNullable​(T instance)
      • get

        public T get()
        Description copied from interface: Lazy
        Return the underlying value, computing the value if necessary. All calls to the same Lazy instance will return the same result.
        Specified by:
        get in interface Lazy<T>
        Specified by:
        get in interface javax.inject.Provider<T>