Syntax for Java 8 lambda expressions:
Syntax: (parameters) -> expression
e.g. (int x, int y) -> x + y
Syntax: (parameters) -> statement
e.g. () -> System.out.println("hi " + s)
Syntax: (parameters) -> { statements }
e.g. (String s) -> { int n = s.length(); return n; }
Syntax for Java 8 method references:
Syntax: Class::staticMethod
e.g. Arrays.sort(items, Util::compareItems);
Syntax: instance::instanceMethod
e.g. items.forEach(System.out::print);
Syntax for Java 8 default methods:
Syntax:
interface InterfaceName {
default ReturnType methodName() {
}
Example code:
interface Descriptive {
default String describe() {
implementation
return "fantastic";
}
}