使用Lombok消除冗长的Java 代码

Lombok通过简单的注解的形式,可以为我们的POJO对象属性生成Getter、Setter、ToStirng()和构造函数等代码。

Lombok的注解主要有:

  1. @Data

    All together now: A shortcut for @ToString, @EqualsAndHashCode, @Getter on all fields, and @Setter on all non-final fields, and @RequiredArgsConstructor!

  2. @Getter / @Setter

    Never write public int getFoo() {return foo;} again.

  3. @ToString No need to start a debugger to see your fields: Just let lombok generate a toString for you!

全部注解参考:https://projectlombok.org/features/index.html

参考:https://projectlombok.org/