Article From:


LombokIt is a tool that can help us to simplify the elimination of some of the necessary but overstaffed Java code by using a simple annotation. By using the corresponding annotations, the corresponding method can be generated when the source code is compiled. Usually, the objects and bean we define need to produce get and se.T method, when it is necessary to create many objects, it is very cumbersome and unsightly. Lombok can save these operations for us through a series of annotations.

Install plug-in

Search and install in the IDEA plug-in Plugins.

Mavenrely on

  1. <!–lombok–>  
  2. <dependency>  
  3.     <groupId>org.projectlombok</groupId>  
  4.     <artifactId>lombok</artifactId>  
  5.     <version>1.16.20</version>  
  6.     <scope>provided</scope>  
  7. </dependency>  

Simple use

  1. package com.preach.model;  
  3. import lombok.Data;  
  5. /** 
  6.  * @author chen 
  7.  * @date 2018-05-25 
  8.  */  
  9. @Data  
  10. public class Student {  
  11.     public String name;  
  12.     public String address;  
  13.     public int age;  
  15.     public static void main(String[] args) {  
  16.         Student student = new Student();  
  17.         student.setAge(24);  
  18.         student.setAddress(“wuhu”);  
  19.         student.setName(“chen”);  
  20.         System.out.printf(student.getName());  
  21.     }  
  22. }  


Look at the structure, the methods such as get and set have been OK.

Common annotation

@DataProvides getting and setting methods for all attributes of the class, and also provides equals, canEqual, hashCode and toString methods.Annotation on the class
@Getter/@SetterProvide the get/set method for the propertyAnnotation on attributes
@NonNullIf this parameter is null, it will throw new NullPointerException (parameter name).Annotation on parameters
@NoArgsConstructorProvide a method of constructing a class without referenceAnnotation on the class
@AllArgsConstructorProvide a full parameter construction method for classAnnotation on the class
@CleanupAuto recovery resource default call close methodAnnotations are before the referenced variable
@ValueIt is an immutable form of @Data, which is equivalent to adding final declarations to attributes, providing getter methods instead of setter methods.On the class

Appendix: IDEA commonly used plug-in collation

Original address:

Link of this Article: IDEA utility plug-in Lombok

Leave a Reply

Your email address will not be published. Required fields are marked *