Lombok annotations Generate Getter/setter methods for Java classes

Source: Internet
Author: User

1, first to Lombok official website Download Lombok.jar Package: http://projectlombok.org/

2, download the following two installation methods:

1. Double-click the downloaded JAR package to install Lombok
I chose to install this way when prompted not to find any IDE, so I did not install successfully, I was installed manually. If you want to install this way, please refer to the website's video.

2.eclipse/myeclipse Manual Installation Lombok
1. Copy the Lombok.jar to the folder directory where the Myeclipse.ini/eclipse.ini resides
2. Open Eclipse.ini/myeclipse.ini, insert the following two lines on the last side and save:
-xbootclasspath/a:lombok.jar
-javaagent:lombok.jar
3. Restart Eclipse/myeclipse

3.Lombok Notes:
Lombok offers a few annotations, and can refer to the official video commentary and official documentation.
Lombok Annotations Online Help documentation: Http://projectlombok.org/features/index.
Here are a few of the Lombok annotations I commonly use:
@Data: Annotations on classes; provides getting and setting methods for all properties of a class, plus equals, canequal, Hashcode, toString methods
@Setter: annotations are on attributes; Provides setting method for attributes
@Getter: annotations are on attributes; provides getting method for attributes
@Log4j: Annotations on a class; Provides a log4j log object with a property named log for the class
@NoArgsConstructor: Annotations on a class; provides an argument-free construction method for a class
@AllArgsConstructor: Annotations are on a class; Provides a method for constructing a full parameter for a class

The following is an example of the annotation generation Getter/setter method

Import Lombok. Getter;import Lombok. Setter;public class User {@Getter @Setter public string name, @Getter @Setter public string password;public static void Mai N (string[] args) {User user = new User (); User.setname ("Zhangsan"); User.setpassword ("1111"); System.out.println (User.getname ()); System.out.println (User.getpassword ());}}
Console result is: Zhangsan
1111

Note: When using these methods, be sure to import the Lombok.jar package in the project first


Lombok annotations Generate Getter/setter methods for Java classes

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.