Recently, my colleague recommended a very useful Java library, let me very much hate their attention to the good things enough, but also lamented the cattle more people, the Java world more open source good things. Here to recommend it to everyone: Lombok.
Lombok is designed to simplify Java code writing, the IDE and compiler (Maven) support Lombok are required. First of all, how to use the specific:
The first step is to download the Lombok jar file https://projectlombok.org/download.html
The second step is to execute it and add it to the classpath of the development IDE eclipse.
3. Start the IDE, add Lombok dependencies to the project, and then add Lombok annotation to the Java file, and then the miracle comes and automatically adds a lot of code that can help simplify development and increase readability.
<dependency>
<groupId>org.projectlombok</groupId>
<artifactid>lombok</ artifactid>
<version>1.16.10</version>
<scope>provided</scope>
</ Dependency>
The Note:lombok function is generate class file, so scope is as good as provided.
Add data, Noargsconstructor, allargsconstructor in eclipse:
Maven compiled class file
Lombok has a lot of functions, can refer to https://projectlombok.org/features/index.html. For me, the usual include: Val, @Getter/@Setter, @NoArgsConstructor, @AllArgsConstructor, @Cleanup, @ToString, @Log4j2, @Slf4j, @ Nonnull
The specific principle can refer to: http://hannesdorfmann.com/annotation-processing/annotationprocessing101
Lombok Source code: https://github.com/rzwitserloot/lombok/