[自荐] - 跟我一起学Lombok 1.16.18
参考Lombok官网学习,中途记录一则。
sequenceDiagram
loop every day
A->>B: How are you?
B->>A: Great!
end
内容更新进度
2017.09.08 Lombok的基本特性罗列;
What is Lombok?
略。
Using Lombok
版本
目前主要有 1.16.18 Download
Install Build Tools
maven
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
<scope>provided</scope>
</dependency>
</dependencies>
gradle
apply plugin: 'java'
apply plugin: 'nebula.provided-base'
repositories {
mavenCentral()
}
dependencies {
provided 'org.projectlombok:lombok:1.16.18'
}
Install IDEs
IntelliJ IDEA
The Jetbrains IntelliJ IDEA editor is compatible with lombok.
Add the Lombok IntelliJ plugin to add lombok support IntelliJ:
Go to File > Settings > Plugins
Click on Browse repositories...
Search for Lombok Plugin
Click on Install plugin
Restart IntelliJ IDEA
MyEclipse
Features-Stable
val
Finally! Hassle-free final local variables.
- 代码
val example = new ArrayList<String>();
- 生成代码
final ArrayList<String> example = new ArrayList<String>();
@NonNull
or: How I learned to stop worrying and love the NullPointerException.
- 代码
- 生成代码
@Cleanup
Automatic resource management: Call your close() methods safely with no hassle.
- 代码
- 生成代码
@Getter/@Setter
Never write public int getFoo() {return foo;} again.
- 代码
- 生成代码
@ToString
No need to start a debugger to see your fields: Just let lombok generate a toString for you!
- 代码
- 生成代码
@EqualsAndHashCode
Equality made easy: Generates hashCode and equals implementations from the fields of your object..
- 代码
- 生成代码
@NoArgsConstructor, @RequiredArgsConstructor and @AllArgsConstructor
Constructors made to order: Generates constructors that take no arguments, one argument per final / non-nullfield, or one argument for every field.
- 代码
- 生成代码
@Data
All together now: A shortcut for @ToString, @EqualsAndHashCode, @Getter on all fields, and @Setter on all non-final fields, and @RequiredArgsConstructor!
- 代码
- 生成代码
@Value
Immutable classes made very easy.
- 代码
- 生成代码
@Builder
… and Bob’s your uncle: No-hassle fancy-pants APIs for object creation!
- 代码
- 生成代码
@SneakyThrows
To boldly throw checked exceptions where no one has thrown them before!
- 代码
- 生成代码
@Synchronized
synchronized done right: Don’t expose your locks.
- 代码
- 生成代码
@Getter(lazy=true)
Laziness is a virtue!
- 代码
- 生成代码
@Log
Captain’s Log, stardate 24435.7: “What was that line again?”
- 代码
- 生成代码
Features-Lombok experimental features
你可以参与的
如果您在阅读中发现文中描述有不正确的地方,欢迎留言指正,留言交流或者在关于我加我微信。
我还可以做的
此文作为学习入门文档,如果后续有新的见解或更有帮助的内容,会持续更新。
参考声明
Lombok features
Reducing Boilerplate Code with Project Lombok
作者:cripps
出处:https://beanstt.github.io
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。