-4

I find a syntax String[]::new in this answer. but I search this in google can't find useful information.

3142 maple
  • 787
  • 1
  • 8
  • 26

2 Answers2

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
  • 44,980
  • 4
  • 53
  • 91
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