Java:: Double colon operator in Java

Source: Internet
Author: User

The double colon operator definition in Java

The double-colon operator is a handle to a class method, a shorthand for a lambda expression called eta-conversion or η-conversion.

The usual case:

Simplify X-System.out.println (x) to System.out: The process of:p Rintln is called eta-conversion

The process of simplifying System.out::p rintln to X, System.out.println (x) is called Eta-expansion

Paradigm:
Class Name:: Method Name

Attention:

    1. method is not followed by ()
    2. Lazy Load method is called to see caller usage
Using the example method call

Person--person.getage ();
Can replace
Person::getage

X-System.out.println (x)
Can replace
System.out::p rintln
Out is an object of the PrintStream class, and println is the method of the class that overloads the method based on the type of X

Creating objects

(), New arraylist<> ();
can be replaced by
Arraylist::new
The New keyword actually calls the construction method of the ArrayList

JVM implementation

The JVM's underlying implementation is callsite, and the interface to the JDK layer burst is functional

Reference

http://hongjiang.info/eta-conversion-and-eta-expansion/

Java:: Double colon operator in Java

Related Article

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.