参数来调用构造函数我有Employee类:在lambda表达式
public class Employee {
private Long id;
private String name;
private String externalId;
public Employee(Long id, String name, String externalId) {
this.id = id;
this.name = name;
this.externalId = externalId;
}
//getters, setter
}
和员工服务返回雇员(NULL是可能的)。
private void performEmployeeProcessing() {
Long employeeId = 2L;
Object o = Optional.ofNullable(employeeService.getById(employeeId))
.orElseGet(Employee::new, 1L, "", "");
System.out.println(o);
}
它说编译错误
员工::新,1L, “”, “”
无法解析构造。
http://stackoverflow.com/questions/29835382/use-method-reference-with-parameter或http://stackoverflow.com/questions/31251629/java-8-supplier-with-arguments-in-the -constructor – Tom