Language

Constructor reference

Adapts construction to the target method. Construction occurs on invocation.

Formal Syntax & Structure

java syntaxjava
Type::new  |  int[]::new

Working Example

Example Snippetjava
import java.util.*;import java.util.function.*;public class Main {
    public static void main(String[] args) {        Supplier<ArrayList<String>> makeList = ArrayList::new;        IntFunction<int[]> makeArray = int[]::new;        List<String> a = makeList.get();        a.add("pen");        System.out.println(a);        System.out.println(makeList.get().size());        System.out.println(makeArray.apply(3).length);    }}
Java Reference