Java 8 Cheatsheet

This is NOT the official website
of Java.
// Lambda expressions
(parameters) -> expression                  e.g.        (int x, int y) -> x + y
(parameters) -> statement                   e.g.        () -> System.out.println("hi " + s)
(parameters) -> { statements }              e.g.        (String s) -> { int n = s.length(); return n; }
 
 
// Method references
Class::staticMethod                         e.g.        Arrays.sort(items, Util::compareItems);
instance::instanceMethod                    e.g.        items.forEach(System.out::print);
 
 
// Default methods
interface InterfaceName {                   e.g.        interface Descriptive {
    default ReturnType methodName() {                       default String describe() {
        implementation                                          return "fantastic";
    }                                                       }
}                                                       }