Lombok plug-in installation and use

1. Download the plug-in https://projectlombok.org/ (lombok.jar file)

2. Run and configure the plug-in

Open the dos window, cd to the directory where the jar file is located, and execute the command java -jar .\lombok.jar

In the opened file, select the IDE that needs to be installed, and then click the "Install/Update" button. As shown below:

 After successful installation, as shown below:

 

In fact, the installation process is to copy lombok.jar to the eclipse directory and add configuration in eclipse.ini, as shown below:

 

3. Use

3.1. Restart IDE;

3.2. The project introduces lombok.jar. If it is a Maven project, introduce the lombok dependency in the pom.xml file:

3.3. Add lombok annotation to the code;

4. Appendix, common annotations for lombok

@NonNull: Field non-null check, if the field is null, a null pointer exception is thrown;

@CleanUp: used on streams, after the stream is read, the close() method is automatically called;

@Setter/@Getter: Automatically generate setter() and getter() methods;

@ToString: automatically generate toString() method;

@EqualsAndHashcode: Automatically generate (override) hashCode() and equals() methods;

@NoArgsConstructor: Automatically generate no-argument constructor;

@RequiredArgsConstructor: Automatically generate a constructor with non-null fields (i.e. fields annotated by @NonNull) as parameters;

@AllArgsConstructor: Contains constructors for all fields;

@Data: Automatically generate set/get methods, toString methods, equals methods, hashCode methods, and constructors without parameters

@Value: used to annotate final classes;

@Builder: Generate complex builder api classes;

@SneakyThrows: exception handling (use with caution);

@Synchronized: safe conversion of synchronized methods;

@Getter(lazy=true): Cache field; refer to https://www.jianshu.com/p/42fd088057dc

@Log: supports various logger objects. Use corresponding annotations when using them, such as: @Log4j

Regarding the use of lombok annotations, please refer to https://www.jianshu.com/p/c943b3871d50

 

Guess you like

Origin blog.csdn.net/u011453631/article/details/126819370