of anonymous class. Lambda expressions are also commonly referred to as
closures.
A
functional interface is an interface that contains one and only one abstract method.
Normally, this method specifies the intended purpose of the interface. Thus, a
functional interface typically represents a single action. For example, the standard
interface Runnable is a functional interface because it defines only one method:
run(). Therefore, run() defines the action of Runnable. Furthermore, a functional
interface defines the
target type of a lambda expression. Here is a key point: a lambda
expression can be used only in a context in which a target type is specified. One other
thing: a functional interface is sometimes referred to as a
SAM type, where SAM stands
for
Single Abstract Method.
Let’s now look more closely at both lambda expressions and functional interfaces.
NOTE
A functional interface may specify any public method defined by Object, such as
equals(), without affecting its “functional interface” status. The public Object
methods are considered implicit members of a functional interface because they are
automatically implemented by an instance of a functional interface.
Lambda Expression Fundamentals
The lambda expression relies on a syntax element and operator that differ from what
you have seen in the preceding chapters. The operator, sometimes referred to as the
Dostları ilə paylaş: