Project Lombok makes java a spicier language by adding ‘handlers’ that know >how to build and compile simple, boilerplate-free, not-quite-java code.
安装与使用
- 定位到 File > Settings > Plugins
- 点击 Browse repositories…
- 搜索 Lombok Plugin
- 点击 Install plugin
- 重启 IDEA
@NonNull
public class NonNullExample extends Something {
private String name;
public NonNullExample(@NonNull Person person) {
super("Hello");
this.name = person.getName();
}
}
翻译成java代码 ==>
public class NonNullExample extends Something {
private String name;
public NonNullExample(@NonNull Person person) {
super("Hello");
if (person == null) {
throw new NullPointerException("person");
}
this.name = person.getName();
}
}
@Cleanup
public class CleanupExample {
public static void main(String\[\] args) throws IOException {
@Cleanup InputStream in = new FileInputStream(args\[0\]);
@Cleanup OutputStream out = new FileOutputStream(args\[1\]);
byte\[\] b = new byte\[10000\];
while (true) {
int r = in.read(b);
if (r == -1) break;
out.write(b, 0, r);
}
}
}
翻译成java代码 ==>
public class CleanupExample {
public static void main(String\[\] args) throws IOException {
InputStream in = new FileInputStream(args\[0\]);
try {
OutputStream out = new FileOutputStream(args\[1\]);
try {
byte\[\] b = new byte\[10000\];
while (true) {
int r = in.read(b);
if (r == -1) break;
out.write(b, 0, r);
}
} finally {
if (out != null) {
out.close();
}
}
} finally {
if (in != null) {
in.close();
}
}
}
}
@Data
相当于
@ToString
@EqualsAndHashCode
@Getter(所有字段)
@Setter (所有非final字段)
@RequiredArgsConstructor
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。