报告记录类并建议将它们转换为普通类。

通过将快速修复应用到此记录,此检查可以将 Java 记录移动到使用早期 Java 版本的代码库。

请注意,生成的类并不完全等同于原始记录:

示例:


  record Point(int x, int y) {}

在应用快速修复后:


  final class Point {
    private final int x;
    private final int y;

    Point(int x, int y) {
      this.x = x;
      this.y = y;
    }

    public int x() { return x; }

    public int y() { return y; }

    @Override
    public boolean equals(Object obj) {
      if (obj == this) return true;
      if (obj == null || obj.getClass() != this.getClass()) return false;
      var that = (Point)obj;
      return this.x == that.x &&
             this.y == that.y;
    }

    @Override
    public int hashCode() {
      return Objects.hash(x, y);
    }

    @Override
    public String toString() {
      return "Point[" +
             "x=" + x + ", " +
             "y=" + y + ']';
    }
  }

仅当项目或模块的语言级别为 15 预览或更高时才报告此检查。

2020.3 的新功能