技巧1:Lombok
-
为 POJO 自动生成 getter / setter / toString 等方法。
-
使用例子:
1 2 3 4 5 6 7 8 9 10 11
@ToString(of = {"name","age"}, exclude={"age"}) @Getter(value = AccessLevel.PUBLIC) @Setter(value = AccessLevel.PUBLIC) @NoArgsConstructor(staticName = "of", access = AccessLevel.PRIVATE) @RequiredArgsConstructor(access = AccessLevel.PACKAGE) @AllArgsConstructor(access = AccessLevel.PUBLIC) public class Person{ @NonNull private String name; private int age; private boolean friendly; }
-
摘录自:Java效率工具之Lombok