September 2019
Intermediate to advanced
816 pages
18h 47m
English
Let's assume that we have the following Melon class and List of Melon:
public class Melon { private final String type; private int weight; public static int growing100g(Melon melon) { melon.setWeight(melon.getWeight() + 100); return melon.getWeight(); } // constructors, getters, setters, equals(), // hashCode(), toString() omitted for brevity}List<Melon> melons = Arrays.asList( new Melon("Crenshaw", 1200), new Melon("Gac", 3000), new Melon("Hemi", 2600), new Melon("Hemi", 1600));
In a nutshell, method references are shortcuts for lambda expressions.
Mainly, method reference is a technique that's used to call a method by name rather than by a description of how to call it. The main benefit is readability.
A method reference ...