在需要开启链式编程的类中加入注解org.projectlombok lombok1.18.2
@Data
@Accessors(chain = true)
public class Person {
private String name;
private int age;
}
就可以愉快的使用链式编程了
private ListgetPersonList(){ return new ArrayList (){{ this.add(new Person().setName("xiaoming").setAge(12)); this.add(new Person().setName("xiaohong").setAge(14)); this.add(new Person().setName("xiaowang").setAge(14)); this.add(new Person().setName("xiaokai").setAge(12)); this.add(new Person().setName("xiaonan").setAge(15)); }}; }



