自定义对象的of生成操作

发布时间 2023-09-18 16:49:40作者: 做时间的好朋友

自定义对象的of生成逻辑

依赖于lombok的注解
@RequiredArgsConstructor(staticName = "of")

  • 写法

@Accessors(chain = true)
@Setter
@Getter
@RequiredArgsConstructor(staticName = "of")
public class Student {
        @NonNull private String name;
        private int age;
}
  • 应用
Student student = Student.of("xiaoming").setAge(20);