1. What is a method reference.
A method reference is a new type of reference for JAVA8, java8 only references to object references and Java base types. To put it simply, adding a reference type is the same as the object reference before Java8.
2. Why increase the method reference.
The main purpose is to increase the readability of the code (easy to read) and simplicity (compact).
We can look at an example, take the sorting method in the Java collection.
Let's first assume that we have a list of the person objects that have a birthday attribute, and we sort the person list in the order of birth.
3. How Java references evolve.
Reference article: http://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html
Let's take an example of how we sort the array, and look at how one of the methods we know is written in the form of a method reference step-by-step.
Let's say we have an array of person objects, and we want to sort the array of person objects by the date of birth.
The person class is as follows:
| 1 2 3 4 5 6 7 8 9 |
public class person { &nbs p; string name; localdate birthday; public calendar getbirthday () { return birthday; } public static int Comparebyage (person a, person b) { |