Java's Lombok

Source: Internet
Author: User

Lombok is a simple form of annotations that can help us simplify the elimination of some of the necessary but very bloated Java code tools, by using the corresponding annotations, you can compile the source code when the corresponding method is generated

Pom dependency:

<dependency>    <groupId>org.projectlombok</groupId>    <artifactid>lombok</ Artifactid></dependency>    

Here are just a few of the frequently used annotations, see https://projectlombok.org/features/index.html

@Getter/@Setter

Can be used on classes and attributes, placed on a class, generates a Getter/setter method on all non-static (Non-static) properties, and on the property, generates Getter/setter methods on the property. You can also specify the access level of the Getter/setter method.

@EqualsAndHashCode

By default, all non-transient (non-transient) and non-static (non-static) fields are used to generate the Equals and Hascode methods, or you can specify which properties are used specifically.

@ToString

Generates the ToString method, which, by default, outputs the class name, all properties, and the attributes are output in sequential order, separated by commas.

@NoArgsConstructor, @RequiredArgsConstructor, @AllArgsConstructor

The parameterless constructor, the partial parameter constructor, and the full parameter constructor, Lombok is powerless when we need to overload multiple constructors.

@Data

@ToString, @EqualsAndHashCode, the @getter of all attributes, the combination of @setter and @requiredargsconstructor of all non-final properties, usually we use this annotation as sufficient

Use the example (the following 5 annotations, you can use only @data annotations instead):

@Getter @setter@tostring@noargsconstructor@equalsandhashcode  Public class userentity {    private  String ID;     Private String lastName;     Private String email;     Private Integer age;}

Java's Lombok

Related Keywords:

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.