What does Java double colon :: mean?

1.Definition

The double colon "::" is a method reference in Java. It is one of the ways to write Lambda expressions in Java 8, a method of executing methods.
To a certain extent, it simplifies the redundant code of our Java development .

2.Use

There are generally 6 usage scenarios for double colon (::).
Insert image description here
For example:

1. Lambda表达式表达式:
person -> person.getName();
可以替换成:
Person::getName

2. Lambda表达式表达式:
() -> new HashMap<>();
可以替换成:
HashMap::new

Guess you like

Origin blog.csdn.net/weixin_42774617/article/details/131029305