我有一个班级User
public class User {
private String firstName;
private String lastName;
private int age;
public User withFirstName(String firstName) {
this.firstName = firstName;
return this;
}
public User withLastName(String lastName) {
this.lastName = lastName;
return this;
}
public User withAge(int age) {
this.age = age;
return this;
}
}
所以我可以使用它初始化它,并且在初始化后,我仍然可以通过.User user = new User().withFirstName("Tom").withAge(30);useruser.withLastName("Bob").withAge(31);
如何利用龙目岛来保存“withXXX”方法?@Builder不是为此用例设计的。
陪伴而非守候
相关分类