preface

“This article has participated in the call for good writing activities, click to view: the back end, the big front end double track submission, 20,000 yuan prize pool waiting for you to challenge!”

Hello everyone, I am ChinaManor, which literally translates to Chinese code farmer. I hope I can become a pathfinder on the road of national rejuvenation, a ploughman in the field of big data, an ordinary person who is unwilling to be mediocre.

Here’s a quick introduction to Lombok to get you started and developing

Lombok is introduced

Lombok makes Java simple and fast by adding “handlers”. Lombok can simplify Java code in the form of annotations to improve development efficiency. Javabeans that are often written in development require time to add getters/setters, perhaps to write constructors, equals, etc., and need to be maintained. Lombok automatically generates constructors, getters/setters, equals, hashcode, and toString methods for properties at compile time via annotations. The magic that happens is that there are no getters and setters in the source code, but there are getters and setters in the bytecode files generated by the compilation. This saves you the trouble of manually rebuilding the code and makes it look cleaner.

Lombok use

Add lombox jar package: lombok-1.18.8.jar. Add the Lombok plug-in for IDEA (for network connection). After the installation is complete, restart IDEA.

Annotations are common in Lombok

@getter and @setter: Generate get and set methods for member variables. Written on a member variable, it is valid for the current member variable. It is written on the class and is valid for all member variables. Note: Static member variables are not valid.

@toString generates the ToString () method. Annotations can only be written on classes.

@noargsconstructor and @allargsconstructor @noargsconstructor: constructor methods without arguments. AllArgsConstructor: Full argument constructor Annotations can only be written on classes.

@equalsandHashCode generates hashCode() and equals(). Annotations can only be written on classes.

@data generates get/set, toString, hashCode, equals, and no argument constructor annotations that can only be written to a class.

Ps: Lombok automatically compiled, symbols do not recognize

If you are using Maven, you can add dependencies directly:

<dependency>

    
<groupId>
org.projectlombok
</groupId>

    
<artifactId>
lombok
</artifactId>

    
<version>
1.168.
</version>

</dependency>
Copy the code

Code examples:

package com.kaplan.pojo;

import lombok.*;

import lombok.extern.log4j.Log4j;

@Getter

@Setter


public class TestDemo {

private String name;

private int age ; 

private String address; 

}


Copy the code

conclusion

That’s a quick Java primer on Lombok

Like small partners welcome a key three even!! I’m Manor, a coder who believes technology is changing the world. See you next time