当前位置:网站首页>Lombok -- simplify code
Lombok -- simplify code
2022-07-03 07:22:00 【Maple Leaf pear flower】
Currently encountered lombok.jar A plug-in for , It is good to use , You can eliminate setter、gettter Methods , Can make the code more concise .
lombok Its official website :https://projectlombok.org/
install
1、 Download... On the official website lombok.jar file
2、 Double-click the downloaded lombok.jar Will help you automatically install . In fact, this step is to lombok.jar Placed in eclipse In the path of , And in eclipse.ini Add... To the last line -javaagent:lombok.jar
annotation
@Getter: Comment on attribute , Provide getter Method ;
@Setter: Comment on attribute , Provide setter Method ;
@AllArgsConstructor: Annotation on class , Provide construction method , Parameters are all attributes ;
@NoArgsConstructor: Annotation on class , Provides a parameterless construction method ;
@Data: Annotation on class , Provide all properties getter Method 、setter Methods and equals、hashCode、toString Other methods ;
@Log: Annotation on class , Provide a name called log Properties of , The type is java.util.logging.Logger, You can also use @Log4j、@Log4j2、@Slf4j And other comments ;
@ToString: Annotation on class , Provide toString Method ;
@EqualsAndHashCode: Annotation on class , Provide equals、hashCode Method ;
@Synchronized: Comment on method , Provide synchronized, You can specify the name of the lock ;
@NonNull: Annotations on method parameters , Provide parameter verification , Prevent null pointer exception ;
@Cleanup: Annotations on local variables , Provide closure of resources , That is to call close Method ;
Simplified code
@NoArgsConstructor
@AllArgsConstructor
public @Data class Person {
private String name;
}After compiling the above code
import java.beans.ConstructorProperties;
public class Person {
private String name;
public Person() {
}
@ConstructorProperties({ "name" })
public Person(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof Person))
return false;
Person other = (Person) o;
if (!other.canEqual(this))
return false;
Object this$name = getName();
Object other$name = other.getName();
return this$name == null ? other$name == null : this$name.equals(other$name);
}
protected boolean canEqual(Object other) {
return other instanceof Person;
}
public int hashCode() {
int PRIME = 59;
int result = 1;
Object $name = getName();
return result * 59 + ($name == null ? 43 : $name.hashCode());
}
public String toString() {
return "Person(name=" + getName() + ")";
}
}This plug-in simplifies a lot of style code , Make the code very clean , However, it will lead to poor readability , Personally, I think it's quite good to use .
边栏推荐
- Advanced API (UDP connection & map set & collection set)
- [HCAI] learning summary OSI model
- Advanced API (serialization & deserialization)
- Advanced API (multithreading)
- Strategy mode
- The difference between typescript let and VaR
- Thoughts on project development
- Longest common prefix and
- 4everland: the Web3 Developer Center on IPFs has deployed more than 30000 dapps!
- Introduction of buffer flow
猜你喜欢

URL programming

Use of file class
![[set theory] partition (partition | partition example | partition and equivalence relationship)](/img/f0/c3c82de52d563f3b81d731ba74e3a2.jpg)
[set theory] partition (partition | partition example | partition and equivalence relationship)

Margin left: -100% understanding in the Grail layout

“百度杯”CTF比赛 2017 二月场,Web:爆破-1
![[set theory] Stirling subset number (Stirling subset number concept | ball model | Stirling subset number recurrence formula | binary relationship refinement relationship of division)](/img/d8/b4f39d9637c9886a8c81ca125d6944.jpg)
[set theory] Stirling subset number (Stirling subset number concept | ball model | Stirling subset number recurrence formula | binary relationship refinement relationship of division)

《指環王:力量之戒》新劇照 力量之戒鑄造者亮相

Le Seigneur des anneaux: l'anneau du pouvoir

1. E-commerce tool cefsharp autojs MySQL Alibaba cloud react C RPA automated script, open source log

Interfaces and related concepts
随机推荐
“百度杯”CTF比赛 2017 二月场,Web:爆破-1
【最詳細】最新最全Redis面試大全(50道)
Thoughts on project development
C WinForm framework
Download address collection of various versions of devaexpress
Take you through the whole process and comprehensively understand the software accidents that belong to testing
Jeecg menu path display problem
Advanced API (multithreading 02)
I. D3.js hello world
Deep learning parameter initialization (I) Xavier initialization with code
CentOS switches and installs mysql5.7 and mysql8.0
Topic | synchronous asynchronous
4everland: the Web3 Developer Center on IPFs has deployed more than 30000 dapps!
【最详细】最新最全Redis面试大全(50道)
[Fiddler actual operation] how to use Fiddler to capture packets on Apple Mobile Phones
Advanced API (character stream & net for beginners)
Crontab scheduled task
Wireshark software usage
GStreamer ffmpeg avdec decoded data flow analysis
Chrome 98 Private Network Access problem w/ disabled web security: Request had no target IP address