Java Reference
In-Depth Information
Here, n is explicitly specified as double . Usually it is not necessary to explicitly specify
the type.
Before moving on, it is important to emphasize a key point: For a lambda expression to
be used in a target type context, the type of the abstract method and the type of the lambda
expression must be compatible. For example, if the abstract method specifies two int para-
meters, then the lambda must specify two parameters whose type either is explicitly int
or can be implicitly inferred as int by the context. In general, the type and number of the
lambda expression's parameters must be compatible with the method's parameters and its
return type.
Lambda Expressions in Action
With the preceding discussion in mind, let's look at some simple examples that put the ba-
sic lambda expression concepts into action. The first example assembles the pieces shown
in the foregoing section into a complete program that you can run and experiment with.
Search WWH ::




Custom Search