当前位置:网站首页>[learning notes] Lombok's @builder annotation
[learning notes] Lombok's @builder annotation
2022-07-27 18:12:00 【Cotton candy】
First of all, I need to understand Builder Pattern :
Define a User class :
public class User {
private String firstName;
private String lastName;
User(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
String firstName;
String lastName;
Builder firstName(String value) {
this.firstName = value;
return this;
}
Builder lastName(String value) {
this.lastName = value;
return this;
}
public User build() {
return new User(firstName, lastName);
}
}
}
Can be called in a chain way User Property of :
User user = User.builder()
.firstName("san")
.lastName("zhang")
.build();
The reason why it can be called in a chain is because User.Builder Class firstName() and lastName() Method returns all of Builder object .
and @Builder The use of annotations can greatly simplify the code :
@Builder
public class User {
private String firstName;
private String lastName;
}
When used, it is the same as before :
User user = User.Build()
.firstName("san")
.lastName("zhang")
.build();
边栏推荐
- vue使用keep-alive实现页面缓存
- 卷积神经网络——SSD论文翻译
- 浅论分布式训练中的recompute机制
- Learn from things | Yidun mobile terminal isomorphism practice, improve the official website interaction experience in a few steps
- Prevent SQL injection
- Understand JVM language
- 解决Reids不能被其他IP访问
- SQL Server连接到服务器无效的解决办法
- Does PostgreSQL 14 support winserver2022?
- 登录页面tableLayout(表格布局)
猜你喜欢

EF框架简介

Set up SSO based on SAML 2.0 in salesforce and enable JIT user provisioning (between SF orgs / between SF org and experience cloud / other IDPs)

The global cloud market is growing rapidly, and data security has entered a strong regulatory era of rule of law

知物由学 | 再造巴别塔,我们如何进行NLP跨语言知识迁移?

Learn from what you know | Yidun self-developed text real-time clustering technology, and wipe out the same kind of harmful content in social networks

Convolutional neural network -- Translation of yolov1 thesis

工信部再治数据安全,网易易盾“隐私合规”守住企业经营底线

浅论分布式训练中的recompute机制

【cf】#681 A. Kids Seating (Div. 2, based on VK Cup 2019-2020 - Final)

IDEA打包war包与war包位置
随机推荐
zabbix6.0的安装部署
How to solve the error of ora-00955 when Oracle modifies the primary key
Convolutional neural network -- Translation of yolov1 thesis
【学习笔记】lombok的@Builder注解
Exciting collection of new features released by salesforce
知物由学 | 关联图分析在反作弊业务中的应用
图形界面编程
【学习笔记】Redis中有序集合zset的实现原理——跳表
Resolve merge fields in salesforce
Year end summary template
Find redundant duplicate records in the table, delete and retain the minimum one
In the first week of June, risk control of e-shield business paid attention to 15 institutions such as New Oriental XRS, which were fined
The latest advanced interview questions for big factories are necessary
卷积神经网络——从R-CNN,Fast R-CNN到Faster R-CNN,Mask R-CNN
年终总结模板
2022 safety officer-c certificate special operation certificate examination question bank and answers
EF框架简介
Prevent SQL injection
Common shell commands (1) -- variable case conversion
CFA exam registration instructions