当前位置:网站首页>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 .
边栏推荐
- [set theory] partition (partition | partition example | partition and equivalence relationship)
- Advanced API (local simulation download file)
- CentOS switches and installs mysql5.7 and mysql8.0
- How to specify the execution order for multiple global exception handling classes
- Arduino Serial系列函数 有关print read 的总结
- Introduction of transformation flow
- Resthighlevelclient gets the mapping of an index
- TCP cumulative acknowledgement and window value update
- php artisan
- Wireshark software usage
猜你喜欢

Arduino Serial系列函数 有关print read 的总结

Dora (discover offer request recognition) process of obtaining IP address

691. 立方体IV

Custom generic structure

Common methods of file class
![[solved] unknown error 1146](/img/f1/b8dd3ca8359ac9eb19e1911bd3790a.png)
[solved] unknown error 1146

专题 | 同步 异步
![Gridome + strapi + vercel + PM2 deployment case of [static site (3)]](/img/65/8d79998e96a2c74ba6e237bee652c6.jpg)
Gridome + strapi + vercel + PM2 deployment case of [static site (3)]

Hash table, generic
![[set theory] partition (partition | partition example | partition and equivalence relationship)](/img/f0/c3c82de52d563f3b81d731ba74e3a2.jpg)
[set theory] partition (partition | partition example | partition and equivalence relationship)
随机推荐
Recursion, Fibonacci sequence
Use of other streams
Custom generic structure
Circuit, packet and message exchange
SharePoint modification usage analysis report is more than 30 days
VMWare网络模式-桥接,Host-Only,NAT网络
TreeMap
Advanced API (UDP connection & map set & collection set)
Interfaces and related concepts
Advanced API (batch image Download & socket dialog)
Summary of abnormal mechanism of interview
Jeecg menu path display problem
Thoughts on project development
为什么说数据服务化是下一代数据中台的方向?
《指環王:力量之戒》新劇照 力量之戒鑄造者亮相
7.2 brush two questions
Docker builds MySQL: the specified path of version 5.7 cannot be mounted.
Basic components and intermediate components
Win 2008 R2 crashed at the final installation stage
专题 | 同步 异步