报告在 Java 记录中声明的冗余构造函数。
示例 1:
record Point(int x, int y) {
public Point {} // 可以移除
}
record Point(int x, int y) {
public Point(int x, int y) { // 可以移除
this.x = x;
this.y = y;
}
}
快速修复移除了冗余的构造函数。
示例 2:
// 可以转换为压缩构造函数
record Range(int from, int to) {
public Range(int from, int to) {
if (from > to) throw new IllegalArgumentException();
this.from = from;
this.to = to;
}
}
快速修复将此代码转换为压缩构造函数。
仅当所配置的语言级别为 14 级或 15 级(预览)时,该检查才会进行报告。
2020.1 的新功能