当前位置:网站首页>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 .
边栏推荐
- Introduction of transformation flow
- The underlying mechanism of advertising on websites
- 萬卷書 - 價值投資者指南 [The Education of a Value Investor]
- Dora (discover offer request recognition) process of obtaining IP address
- File operation serialization recursive copy
- 深度学习参数初始化(一)Xavier初始化 含代码
- 7.2刷题两个
- Gridome + strapi + vercel + PM2 deployment case of [static site (3)]
- 【已解决】win10找不到本地组策略编辑器解决方法
- PAT甲级真题1166
猜你喜欢

你开发数据API最快多长时间?我1分钟就足够了

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

691. Cube IV

Distributed transactions

Final, override, polymorphism, abstraction, interface

Docker builds MySQL: the specified path of version 5.7 cannot be mounted.

Common APIs

4279. 笛卡尔树

Introduction of transformation flow

Summary of Arduino serial functions related to print read
随机推荐
Strategy mode
[set theory] partition (partition | partition example | partition and equivalence relationship)
Recursion, Fibonacci sequence
[untitled]
Spa single page application
Advanced API (local simulation download file)
Jeecg data button permission settings
dataworks自定義函數開發環境搭建
GStreamer ffmpeg avdec decoded data flow analysis
Introduction of transformation flow
When MySQL inserts Chinese into the database, there is a diamond question mark garbled code
LeetCode
[set theory] equivalence classes (concept of equivalence classes | examples of equivalence classes | properties of equivalence classes | quotient sets | examples of quotient sets)*
C代码生产YUV420 planar格式文件
2021-07-18
[plus de détails] dernière entrevue complète redis (50)
Margin left: -100% understanding in the Grail layout
Wireshark software usage
万卷书 - 价值投资者指南 [The Education of a Value Investor]
CentOS switches and installs mysql5.7 and mysql8.0