Interface Function<F,T>
-
- All Known Subinterfaces:
LoadingCache<K,V>
- All Known Implementing Classes:
AbstractLoadingCache
,Converter
,ForwardingLoadingCache
,ForwardingLoadingCache.SimpleForwardingLoadingCache
@GwtCompatible public interface Function<F,T>
Determines an output value based on an input value; a pre-Java-8 version ofjava.util.function.Function
.The
Functions
class provides common functions and related utilities.See the Guava User Guide article on the use of
Function
.For Java 8+ users
This interface is now a legacy type. Use
java.util.function.Function
(or the appropriate primitive specialization such asToIntFunction
) 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 function (say, named
function
) in a context where the other type of function is expected, use the method referencefunction::apply
. A future version ofcom.google.common.base.Function
will be made to extendjava.util.function.Function
, making conversion code necessary only in one direction. At that time, this interface will be officially discouraged.- Since:
- 2.0
- Author:
- Kevin Bourrillion
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description T
apply(F input)
Returns the result of applying this function toinput
.boolean
equals(Object object)
May returntrue
ifobject
is aFunction
that behaves identically to this function.
-
-
-
Method Detail
-
apply
@CanIgnoreReturnValue @NullableDecl T apply(@NullableDecl F input)
Returns the result of applying this function toinput
. This method is generally expected, but not absolutely required, to have the following properties:- Its execution does not cause any observable side effects.
- The computation is consistent with equals; that is,
Objects.equal
(a, b)
implies thatObjects.equal(function.apply(a), function.apply(b))
.
- Throws:
NullPointerException
- ifinput
is null and this function does not accept null arguments
-
equals
boolean equals(@NullableDecl Object object)
May returntrue
ifobject
is aFunction
that behaves identically to this function.Warning: do not depend on the behavior of this method.
Historically,
Function
instances in this library have implemented this method to recognize certain cases where distinctFunction
instances would in fact behave identically. However, as code migrates tojava.util.function
, that behavior will disappear. It is best not to depend on it.- Overrides:
equals
in classObject
- Parameters:
object
- the reference object with which to compare.- Returns:
true
if this object is the same as the obj argument;false
otherwise.- See Also:
Object.hashCode()
,HashMap
-
-