Project Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java. Never write another getter or equals method again, with one annotation your class has a fully featured builder, Automate your logging variables, and much more.
@Data
All together now: A shortcut for @ToString, @EqualsAndHashCode, @Getter on all fields, @Setter on all non-final fields, and @RequiredArgsConstructor!
The builder annotation creates a so-called 'builder' aspect to the classthatisannotatedortheclassthatcontainsamemberwhichisannotatedwith @Builder. Ifamemberisannotated, itmustbeeitheraconstructororamethod. Ifaclassisannotated, thenapackage-privateconstructorisgeneratedwithallfieldsasarguments (asif @AllArgsConstructor(access= AccessLevel.PACKAGE) is present on the class), anditisasifthisconstructorhasbeenannotatedwith @Builderinstead. Notethatthisconstructorisonlygeneratedifyouhaven'twrittenanyconstructorsandalsohaven'taddedanyexplicit @XArgsConstructorannotations. Inthosecases, lombokwillassumeanall-argsconstructorispresentandgeneratecodethatusesit; this means you'd get a compiler error if this constructor is not present. The effect of @Builder is that an inner class is generated named TBuilder, with a private constructor. Instances of TBuilder are made with the method named builder() which is also generated for you in the class itself (not in the builder class). The TBuilder class contains 1 method for each parameter of the annotated constructor / method (each field, when annotating a class), which returns the builder itself. The builder also has a build() method which returns a completed instance of the original type, created by passing all parameters as set via the various other methods in the builder to the constructor or method that was annotated with @Builder. The return type of this method will be the same as the relevant class, unless a method has been annotated, in which case it'll be equal to the return type of that method. Complete documentation is found at the project lombok features page for@Builder . Before: @Builder classExample<T> { private T foo; privatefinal String bar; } After: classExample<T> { private T foo; privatefinal String bar; privateExample(T foo, String bar){ this.foo = foo; this.bar = bar; } publicstatic <T> ExampleBuilder<T> builder(){ returnnew ExampleBuilder<T>(); } publicstaticclassExampleBuilder<T> { private T foo; private String bar; privateExampleBuilder(){} public ExampleBuilder foo(T foo){ this.foo = foo; returnthis; } public ExampleBuilder bar(String bar){ this.bar = bar; returnthis; } @java.lang.Override public String toString(){ return"ExampleBuilder(foo = " + foo + ", bar = " + bar + ")"; } public Example build(){ returnnew Example(foo, bar); } } }