Java Reference
In-Depth Information
Sorted by the first name:
Donna Jacobs, FEMALE, 1970-09-12
John Jacobs, MALE, 1975-01-20
Wally Inman, MALE, 1965-09-12
Sorted by the last name, first name, and dob:
Wally Inman, MALE, 1965-09-12
Donna Jacobs, FEMALE, 1970-09-12
John Jacobs, MALE, 1975-01-20
Summary
A lambda expression is an unnamed block of code (or an unnamed function) with a list of formal parameters and a
body. A lambda expression provides a concise way, as compared with anonymous inner classes, to create an instance
of functional interfaces. Lambda expressions and default methods in interfaces have given new life to the Java
programming languages as far as expressiveness and fluency in Java programming goes. The Java collection library
has benefited the most from lambda expressions.
The syntax for defining lambda expressions is similar to declaring a method. A lambda expression may have a list
of formal parameters and a body. A lambda expression is evaluated to an instance of a functional interface. The body
of the lambda expression is not executed when the expression is evaluated. The body of the lambda expression is
executed when the method of the functional interface is invoked.
One of the design goals of lambda expressions was to keep it concise and readable. The lambda expression syntax
supports shorthand for common use cases. Method references are shorthand to specify lambda expressions that use
existing methods.
A poly expression is an expression whose type depends on the context of its use. A lambda expression is always a
poly expression. A lambda expression cannot be used by itself. Its type is inferred by the compiler from the context.
A lambda expression can be used in assignments, method invocations, returns, and casts.
When a lambda expression occurs inside a method, it is lexically scoped. That is, a lambda expression does not
define a scope of its own; rather, it occurs in a method's scope. A lambda expression may use the effectively final local
variables of a method. A lambda expression may use the statements such as break , continue , return , and throw . The
break and continue statements specify local jumps inside the body of the lambda expression. Attempting to jump
outside the body of the lambda expression generates a compile-time error. The return and throw statements exit the
body of the lambda expression.
 
Search WWH ::




Custom Search