June 2017
Beginner
1296 pages
69h 23m
English
Lambda expressions can be used anywhere functional interfaces are expected. The Java compiler can usually infer the types of a lambda’s parameters and the type returned by a lambda from the context in which the lambda is used. This is determined by the lambda’s target type—the functional-interface type that’s expected where the lambda appears in the code. For example, in the call to IntStream method map from stream pipeline in Fig. 17.4
IntStream.rangeClosed(1, 10)
.map((int x) -> {return x * 2;})
.sum()
the target type is IntUnaryOperator, which represents a method that takes one int parameter and returns an int result. In this case, the lambda parameter’s type is explicitly ...
Read now
Unlock full access