Java Reference
In-Depth Information
and instantiate it directly inline. The following code is valid because Runnable is a functional
interface defining only one abstract method, run:
3.2.2. Function descriptor
The signature of the abstract method of the functional interface essentially describes the
signature of the lambda expression. We call this abstract method a function descriptor . For
example, the Runnable interface can be viewed as the signature of a function that accepts
nothing and returns nothing (void) because it has only one abstract method called run, which
accepts nothing and returns nothing (void). [ 1 ]
1 Some languages such as Scala provide explicit type annotations in their type system to describe
the type of a function (called function types). Java reuses existing nominal types provided by
functional interfaces and maps them into a form of function types behind the scenes.
We use a special notation throughout the chapter to describe the signatures of lambdas and
functional interfaces. The notation () -> void represents a function with an empty list of
parameters returning void. This is exactly what the Runnable interface represents. As another
example, (Apple, Apple) -> int denotes a function taking two Apples as parameters and
returning an int. We'll provide more information about function descriptors in section 3.4 and
table 3.2 later in the chapter.
Table 3.2. Common functional interfaces in Java 8
Functional
interface
Function
descriptor
Primitive specializations
 
Search WWH ::




Custom Search