Reference-java8 new attribute of method

Source: Internet
Author: User

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)  {

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.