Lombok simplifying Java code

Source: Internet
Author: User
Tags log4j

Guide package: Import Lombok. Data;

Lombok simplifies Java code:

In Lombok, there are altogether three annotation to generate a constructor method:
@NoArgsConstructor, @RequiredArgsConstructor, @AllArgsContructor. The
uses these three annotation to complete the requirements for different construction methods in the project.
@NoArgsConstructor: Generates a parameterless construction method that highlights the importance of this annotation when used in conjunction with other annotation,
For example, when using the Hibernate framework, If there is an argument to the construction method, Noargsconstructor will show his role.
@RequiredArgsConstructor: A construction method that contains constants, and variables that identify Notnull, is generated. The build method is private, and you can use the Staticname option to generate a static method if you want to provide it externally.
@AllArgsContructor:? Generates a check that contains all the variables, and if the variable uses notnull annotation, it will be empty.


Here are a few of the Lombok annotations I use frequently:
        @Data  : Annotations on classes, providing getting and setting methods for all properties of the class, plus the Equals, canequal, Hashcode, toString methods br>        @Setter: annotations on attributes; Provides setting methods for properties
        @Getter: annotations on attributes; provides gettin for properties G Method
        @Log4j: Annotations on classes; Provides a log4j log object with a property name of log
        @NoArgsConstr Uctor: Annotations on classes; provides an argument-free construction method for a class
        @AllArgsConstructor: Annotations on a class, and a method to construct a full parameter for a class

Lombok simplifying Java code

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.