// Before
Runnable oldRunner = new Runnable(){
public void run(){
System.out.println("I am running");
}
};
// After
Runnable java8Runner = () -> {
System.out.println("I am running");
};
// Before
inventory.sort((Apple a1, Apple a2) ->
a1.getWeight().compareTo(a2.getWeight()));
// After
inventory.sort(comparing(Apple::getWeight));
/*
Lamda -> Method Reference
(Apple a) -> a.getWeight Apple::getWeight
() -> Thread.currentThread().dumpStack() Thread.currentThread()::dumpStack
*/
// Before
List<Shape> list = new ArrayList<Shape>();
for (Shape s : shapes) {
if (s.getColor() == RED) {
list.add(s);
}
}
// After
shapes.stream().filter(s -> s.getColor() == Red).collect(toList());
shapes.parallelStream().forEach(s -> doSomething());
public interface Sized {
int size();
default boolean isEmpty() { // Default Method
return size() == 0;
}
}