当前位置:网站首页>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 .
边栏推荐
- FileInputStream and fileoutputstream
- 691. Cube IV
- Advanced API (UDP connection & map set & collection set)
- dataworks自定義函數開發環境搭建
- 1. E-commerce tool cefsharp autojs MySQL Alibaba cloud react C RPA automated script, open source log
- Mise en place d'un environnement de développement de fonctions personnalisées
- 10 000 volumes - Guide de l'investisseur en valeur [l'éducation d'un investisseur en valeur]
- Talk about floating
- Dora (discover offer request recognition) process of obtaining IP address
- Jeecg data button permission settings
猜你喜欢
![[Fiddler problem] solve the problem about Fiddler's packet capturing. After the mobile network is configured with an agent, it cannot access the Internet](/img/9d/42dfef67246740f0dba0c6d8f1b625.jpg)
[Fiddler problem] solve the problem about Fiddler's packet capturing. After the mobile network is configured with an agent, it cannot access the Internet

Dora (discover offer request recognition) process of obtaining IP address
![[set theory] partition (partition | partition example | partition and equivalence relationship)](/img/f0/c3c82de52d563f3b81d731ba74e3a2.jpg)
[set theory] partition (partition | partition example | partition and equivalence relationship)

Interview questions about producers and consumers (important)

SecureCRT password to cancel session recording

Circuit, packet and message exchange
![[solved] unknown error 1146](/img/f1/b8dd3ca8359ac9eb19e1911bd3790a.png)
[solved] unknown error 1146

Interfaces and related concepts

Selenium key knowledge explanation
![[HCAI] learning summary OSI model](/img/90/66505b22e32aa00b26886a9d5c5e4c.jpg)
[HCAI] learning summary OSI model
随机推荐
Map interface and method
Wireshark software usage
Download address collection of various versions of devaexpress
Advanced API (use of file class)
PHP install the spool extension
Common architectures of IO streams
"Baidu Cup" CTF game 2017 February, Web: blast-1
4279. 笛卡尔树
Advanced API (byte stream & buffer stream)
Warehouse database fields_ Summary of SQL problems in kingbase8 migration of Jincang database
691. Cube IV
2021-07-18
20220319
C WinForm framework
Common methods of file class
Advanced API (multithreading)
sharepoint 2007 versions
Discussion on some problems of array
Advanced API (serialization & deserialization)
Hash table, generic