Interface Supplier<T extends @Nullable java.lang.Object>


  • @GwtCompatible
    public interface Supplier<T extends @Nullable java.lang.Object>
    A class that can supply objects of a single type; a pre-Java-8 version of java.util.function.Supplier. Semantically, this could be a factory, generator, builder, closure, or something else entirely. No guarantees are implied by this interface.

    The Suppliers class provides common suppliers and related utilities.

    See the Guava User Guide article on the use of functional types.

    For Java 8+ users

    This interface is now a legacy type. Use java.util.function.Supplier (or the appropriate primitive specialization such as IntSupplier) instead whenever possible. Otherwise, at least reduce explicit dependencies on this type by using lambda expressions or method references instead of classes, leaving your code easier to migrate in the future.

    To use an existing supplier instance (say, named supplier) in a context where the other type of supplier is expected, use the method reference supplier::get. A future version of com.google.common.base.Supplier will be made to extend java.util.function.Supplier, making conversion code necessary only in one direction. At that time, this interface will be officially discouraged.

    Since:
    2.0
    Author:
    Harry Heymann
    • Method Detail

      • get

        T get()
        Retrieves an instance of the appropriate type. The returned object may or may not be a new instance, depending on the implementation.
        Returns:
        an instance of the appropriate type