=============================
Java double colon:: Meaning of the syntax
=============================
The following code has a double colon, which looks strange at first,
List.foreach (System.out::p rintln);
This is the Java8 "method reference", the syntax is the class name:: Static method name, generally used as a simplified LAMDA expression.
See discussion: https://www.zhihu.com/question/28565691
Like what:
List.foreach (System.out::p rintln) equivalent to List.foreach (I->SYSTEM.OUT.PRINTLN (i))
Namelist.foreach (person::new) equivalent to Namelist.foreach (name->new person (name))
=============================
Java Three dots ... Meaning of the parameter
=============================
Java 1.5 introduces three points ... syntax, you can change the parameter syntax. Since it is a mutable parameter syntax, it can only be used for function parameter definitions, and it can only be used in the last parameter. In the function body, the variable parameter can be considered an array; In the context of a function call, you can pass in an array argument, or 0 arguments, or multiple arguments.
A variable parameter function is more flexible than a normal array parameter function. See Example:
Public classapp{Static voidtest1 (string...names) { for(String name:names) {System.out.println (name); } System.out.println ("End of Test1"); } Static voidtest2 (string[] names) { for(String name:names) {System.out.println (name); } System.out.println ("End of Test2"); } Public Static voidMain (string[] args) {test1 (NewString[] {"A", "B"}); Test1 ("A", "B"); Test1 (); //It can even be passed without arguments .Test2 (NewString[] {"A", "B"}); //test2 (); //do not pass arguments will report syntax errorsTest2 (NewString[] {});//An empty array, equivalent to not passing arguments }}
Some strange grammar of Jjava