Constructor & Array Reference in Lambda Expression
1. Constructor format:
ClassName::new
2. Constructor instance
@Test
public void test5(){
//原来的方法
Supplier<Employee> supplier = ()->new Employee();
//构造器应用
Supplier<Employee> supplier1 = Employee::new;
Employee employee = supplier1.get();
System.out.println(employee);
}
3. Constructor description
For a class with multiple constructors, the constructor reference call is matched according to the parameter list of the functional method
4. Array reference
Type::new
@Test
public void test6(){
//原来的方法
Function<Integer,String[]> function = (x)->new String[x];
String[] apply = function.apply(10);
//数组引用
Function<Integer,String[]> function1 = String[]::new;
String[] apply1 = function1.apply(20);
System.out.println(apply1.length);
}