Project Lombok is a java library that automatically plugs into your editor and
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.
Project Lombok webpage: https://projectlombok.org/
How Lombok Works
- Hooks in via the Annotation processor API
- The AST (raw source code) is passed to Lombok for code generation before java continues.
- Thus, produces properly compiled Java code in conjunction with the Java compiler
Project Lombok and IDEs
- Since
compiled code is changed, and source files are not, IDE’s can get confused by this. - Modern IDEs such as IntelliJ, Eclipse, Netbeans support Project Lombok
- Plugin Installation may be necessary
Project Lombok Features
- @Getter – Creates getter methods for all properties
- @Setter – Creates setter for all non-final properties
- @ToString – Generates String of classname, and each field separated by commas; Optional parameter to include field names; Optional parameter to include the call to the super toString method
- @EqualsAndHashCode – Generates implementations of ‘equals(Object other) and hashCode(); By default will use all non-static, non-transient properties; Can optionally exclude specific properties.
- @NoArgsConstructor – Generates no-args constructor; Will cause compiler error if there are final fields; Can optionally force, which will initialize final fields with 0 /
false / null - @RequiredArgsContructor – Generates a constructor for all fields that are final or marked @NonNull; Constructor will throw a NullPointerException if any @NonNull fields are null.
- @Data – Generates typical boilerplate code for POJOs, Combines – @Getter, @Setter, @ToString, @EqualsAndHashCode, @RequiredArgsConstructor; No constructor is generated if constructors have been explicitly declared.
- @Value – The immutable variant of @Data; All fields are made private and final by default.
- @NotNull – Set on a parameter of method or constructor and a NullPointerException will be thrown if the parameter is null.
- @Builder – Implements the ‘builder’ pattern for object creation.
- @SneakyThrows – Throw checked exceptions without declaring in calling method’s throws clause.
- @Syncronized – A safer implementation of Java’s synchronized
- @Log – Creates a Java
util logger. - @Slf4j – Creates a SLF4J logger.