val,var, 只能用在局部变量
val = final var;
@NonNull 这个好像没什么好说的
import lombok.NonNull; |
@CleanUp 清除缓存 自动添加 close等方法,清除缓存
import lombok.Cleanup;
import java.io.*;
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);
}
}
}
@Getter and @Setter
正常用法 @Getter @Setter private int age = 10;
@Setter(AccessLevel.PROTECTED) private String name;
// AccessLevel可以控制生成的 @Getter @Setter的修饰等级,参数:PUBLIC, PROTECTED, PACKAGE, and PRIVATE.
// 默认为 PUBLIC
@Tostring
@ToString(callSuper=true, includeFieldNames=true)
public static class Square extends Shape {
private final int width, height;
public Square(int width, int height) {
this.width = width;
this.height = height;
}
}
}
// 写在类前,有多个参数可选,主要是 callSuper, includeFieldNames,exclude
@Value 构建final类与@Wither 联用
@Value public class ValueExample {
String name;
@Wither(AccessLevel.PACKAGE) @NonFinal int age;
double score;
protected String[] tags;
@ToString(includeFieldNames=true)
@Value(staticConstructor="of")
public static class Exercise<T> {
String name;
T value;
}
}
@Wither(AccessLevel.PACKAGE) @NonFinal int age;
相当于
ValueExample withAge(int age) {
return this.age == age ? this : new ValueExample(name, age, score, tags);
}
用于修改 final类的内容 // 返回一个新的对象
@Builder 用于创建builder模式
@Builder |
BuilderExample be = new BuilderExample().name("sss")…………;
@SneakyThrows 异常处理,添加try{}catch{};
@Synchronized 加锁;
@Getter(lazy=true) 节约计算和缓存;
@Log 奇怪的log