9、Lombok
Project Lombok is a Java library that is automatically plugged into editors and build tools. Lombok provides a useful set of annotations to eliminate a lot of boilerplate code in Java classes. Just five characters (@Data) can replace hundreds of lines of code resulting in clean, concise, and easy-to-maintain Java classes.
Steps for usage:
-
Install the Lombok plugin in IDEA
-
Import the jar package of lombok in the project
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
<scope>provided</scope>
</dependency>
3. Annotate the program
@Getter and @Setter
@FieldNameConstants
@ToString
@EqualsAndHashCode
@AllArgsConstructor, @RequiredArgsConstructor and @NoArgsConstructor
@Log, @Log4j, @Log4j2, @Slf4j, @XSlf4j, @CommonsLog, @JBossLog, @Flogger, @CustomLog
@Data
@Builder
@SuperBuilder
@Singular
@Delegate
@Value
@Accessors
@Wither
@With
@SneakyThrows
@val
illustrate:
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User {
private int id;
private String name;
private String password;
}