Lombok plugin,

Source: Internet
Author: User

Lombok plugin,

IDE:

IntelliJ IDEA

First install lombok in the configured plug-in bar, and then use the following pom dependency:

<dependency>   <groupId>org.projectlombok</groupId>    <artifactId>lombok</artifactId>    <optional>true</optional></dependency>
Annotations:
  • @ ToString

 

Generate the toString () method. By default, it prints your class name and each field in order (separated by commas. You can set the fields that do not contain @ ToString (exclude = "id")/@ ToString (exclude = {"id", "name"}). If the inherited fields have parent classes, you can set callSuper to call the toString () method of the parent class, for example, @ ToString (callSuper = true)

 

Import lombok. toString; @ ToString (exclude = {"id", "name"}) public class User {private Integer id; private String name; private String phone ;} // The toString generation method is as follows: public String toString () {return "User (phone =" + phone + ")";}
  • @ Getter and @ Setter
You can use @ Getter/@ Setter to comment out any field, so that lombok can automatically generate the default getter/setter method. The default method is public. To modify the method modifier, you can set the value of AccessLevel, for example, @ Getter (access = AccessLevel. PROTECTED)
import lombok.AccessLevel;import lombok.Getter;import lombok.Setter;public class User {     @Getter(AccessLevel.PROTECTED) @Setter private Integer id;     @Getter @Setter private String name;     @Getter @Setter private String phone;}
  • @ Override sandhashcode
Generate hashCode () and equals () methods,
By default, it uses all non-static and non-transient fields. However, you can exclude more fields by using the optional exclude parameter. Alternatively, you can name them in the parameter to specify the fields you want to use.
  • @ RequiredArgsConstructor
@ RequiredArgsConstructor: A constructor generates a constructor (which may contain parameters or not). If a constructor contains parameters, this parameter can only be a final modified uninitialized field, or an uninitialized field @ RequiredArgsConstructor (staticName = "of") annotated with @ NonNull will generate a static method of () and set the constructor to private
  • @ Data
@ Data contains the functions of @ ToString, @ javassandhashcode, @ Getter/@ Setter, and @ RequiredArgsConstructor.

More useful information will be added in the future.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.