Preface:

At the new company, lombok was found in the code. I would like to recommend it. Lombok provides the form of simple annotations to help simplify and eliminate some of the necessary but bloated Java code. Especially relative to POJOs, take a look.

Lombok’s official website:

projectlombok.org/

Lombok’s 3:49 second video on the website is clear and well documented.

Lombok installation:

To use Lombok, you need to install it, and without it, the IDE cannot parse Lombok annotations. Download the latest JAR package from the official website. The latest version is 1.16.8.

1. Double-click the downloaded JAR package to install Lombok

When I chose to install this way, there was no IDE found, so I failed to install, I installed manually. If you want to install it this way, check out the video on the website.

Eclipse/myEclipse manually install Lombok

  1. Copy lombok.jar to the folder directory where myeclipse.ini/eclipse.ini is located
  2. Open the eclipse. Ini/myeclipse. Ini, behind the insert the following two lines and save: – Xbootclasspath/a: lombok. Jar – javaagent: lombok. Jar

3. Restart Eclipse/myEclipse

Lombok annotations

Lombok does not provide many annotations, but you can refer to the official video explanation and official documentation. Lombok comments online help document: projectlombok.org/features/in… .

Here are a few common Lombok notes:

<span style="color:#006600;"> @data: can omit allset/get method @get: can be omitted @set: can be omittedsetMethod @allargsconstructor: all-parameter constructor @noargsconstructor: no-parameter constructor @Builder: similar to a factory-generated object @log4j2: generates onelog</span>Copy the code

Specific examples:

@data @allargsconstructor @noargsconstructor @builder public class User {// @data @allargsconstructor @noargsconstructor @constructor public class Userset/get method private String userName; private int age; Public static void main(String[] args) {// create object User User = user.builder ().username ()"Make force").age(12).build(); // Call directlyset/ get methods user. GetUserName (); }}Copy the code

Lombok is obviously much cleaner, especially if the class has more attributes, and avoids the silly mistake of forgetting to change method names when changing field names. Finally, remember to import lombok. Jar into your project when using Lombok annotations.

The reason why someone is always better than you is because they are already better and are constantly trying to become better, while you are still satisfied with the status quo and secretly happy!

Rational use of their every minute every second of time to learn to improve themselves, do not use “no time” to cover up their ideological laziness! While young, hard to fight, to the future of their own account!

To-morin Java architectureCopy the code

Share the latest Internet articles to pay attention to the latest development of the Internet