Employee对象
public class Employee {
private String id;
private String name;
private int age;
private String hobby;
private String address;
public Employee() {
this.id = "auto:"+UUID.randomUUID().toString();
}
public Employee(String id) {
this.id = id;
}
public Employee(String id, String name) {
this.id = id;
this.name = name;
}
public Employee(String id, String name, int age) {
this.id = id;
this.name = name;
this.age = age;
}
public Employee(String id, String name, int age, String hobby) {
this.id = id;
this.name = name;
this.age = age;
this.hobby = hobby;
}
@Override
public String toString() {
return "Employee{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", age=" + age +
", hobby='" + hobby + '\'' +
", address='" + address + '\'' +
'}';
}
}
// 无构造函数 需要通过Supplier来实现
Supplier<Employee> supplier = Employee::new;
Employee noPara = supplier.get();
System.out.println("noPara="+noPara);
// 1个参数构造函数
Function<String,Employee> oneParaFunction = (s) -> new Employee(s);
Employee onePara = oneParaFunction.apply("1");
System.out.println("onePara="+onePara);
// 2个构造函数
BiFunction<String,String,Employee> twoParaFunction = (id, name) -> new Employee(id,name);
Employee twoPara = twoParaFunction.apply("2","two");
System.out.println("twoPara="+twoPara);
// 3个构造函数 2个以上需要自己扩展接口 ThreeFunction
ThreeFunction<String,String,Integer,Employee> threeFunction = (id,name,age) -> new Employee(id,name,age);
Employee threePara = threeFunction.apply("3","three",18);
System.out.println("threePara="+threePara);
// 4个构造函数 FourFunction
FourFunction<String,String,Integer,String,Employee> fourFunction = (id,name,age,hobby) -> new Employee(id,name,age,hobby);
Employee fourPara = fourFunction.apply("4","four",18,"football");
System.out.println("fourPara="+fourPara);