Item 42: Prefer lambdas to anonymous classes

Anonymous classes were adequate for the classic objected-oriented design patterns requiring function objects. Here’s a code snippet using an anonymous class. // Anonymous class instance as a function object – obsolete! Collections.sort(words, new Comparator<String>() { public int compare(String s1, String s2) { return Integer.compare(s1.length(), s2.length()); } }); Interfaces with a single abstract method are now

Read More

Item 20: Prefer interfaces to abstract classes

Advantages Existing classes can easily be reconstructed to implement a new interface. You just need to use implements clause to the class declaration and add the required methods Interfaces are ideal for defining mixins (Example: http://hannesdorfmann.com/android/java-mixins) Interfaces allow for the construction of non-hierarchical type frameworks. They are great for organizing things that don’t fall into a hierarchy

Read More