Interface Supplier<T extends @Nullable Object>
-
@GwtCompatible public interface Supplier<T extends @Nullable Object>
A class that can supply objects of a single type; a pre-Java-8 version ofjava.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 asIntSupplier
) 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 referencesupplier::get
. A future version ofcom.google.common.base.Supplier
will be made to extendjava.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 Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description T
get()
Retrieves an instance of the appropriate type.
-