I find a syntax String[]::new in this answer. but I search this in google can't find useful information.
Asked
Active
Viewed 133 times
2 Answers
1
This is actually a shorthand for a lambda, a recent addition to Java:
size -> new String[size]
which in turn is shorthand for an IntFunction:
new IntFunction<String[]> {
@Override
String[] apply(int size) {
return new String[size];
}
}
As you can see, these additions to Java 8 make the language a bit less verbose.

Gene
- 46,253
- 4
- 58
- 96
0
This is a method reference to a constructor. The ClassName::method
is just a terser syntax for using lambda expressions that call existing methods (in this case new
), as opposed to those which call anonymous methods.

jchaffin
- 65
- 8