Lombok common comment

chilli

Lombok in a simple comment form java code to simplify and improve the development efficiency of the developer. Such as development often need to write javaBean, need to take the time to add the corresponding getter / setter, and perhaps to write a constructor, equals methods, and the need to maintain, for a long time when a large number of property getter / setter methods occur, these seemed very long without much technical content, once modify the properties, it is prone to forget to change the mistakes of the corresponding method.

Annotations can Lombok manner, at compile time automatically generated constructor property, getter / setter, equals, hashcode, toString method. It appears that there is no magic getter and setter methods in the source code, but there are getter and setter methods in the compiled byte code file. This eliminates the need to manually rebuild the trouble code, making the code look more succinctly.

Common Annotations

annotation description
@Data @Data annotation on the class, setter / getter, equals, canEqual, hashCode, toString method automatically generates classes for all properties, such as the final attribute, no attribute setter method for the generation.
@Getter/@Setter Annotations on this property may be automatically generated Getter / Setter method corresponding properties, it may also be declared directly in the class.
@NonNull Notes @NonNull need for empty check. When placed in the field generated Lombok setter methods will generate an empty inspection, which will result in NullPointerException should provide a null value. In addition, if the class generation Lombok to have a constructor, this field is added to the signature constructor, and included in the inspection null constructor code generated.
@Cleanup The notes can help us to automatically call close () method, greatly simplifies the code.
@EqualsAndHashCode By default, it will use all non-static (non-static) and non-transient (non-transient) attribute is generated and equals hasCode, can also exclude annotation to exclude some properties.
@ToString Use @ToString annotations, Lombok is generated a toString () method, by default, will output class names, all attributes (attribute defines the order will follow), divided by a comma. By includeFieldNames parameter set to true, you can clear the output of toString () property.
@NoArgsConstructor No-argument constructor
@RequiredArgsConstructor Some parameters constructor
@AllArgsConstructor Full-argument constructor

IDEA use Lombok

1. First introduced dependencies

<dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>version</version>
 </dependency>

2. Install the plug-in: keyword search lombok installed can be used.
Here Insert Picture Description

Guess you like

Origin blog.csdn.net/qq_16830879/article/details/89524500