Suggests replacing classes with records.

The inspection can be useful if you need to focus on modeling immutable data rather than extensible behavior. Automatic implementation of data-driven methods, such as equals and accessors, helps to get rid of boilerplate.

Note that not every class can be a record. Here are some of the restrictions:

To get a full list of the restrictions, refer to the Oracle documentation.

Example:


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

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

    double getX() {
      return x;
    }

    double getY() {
      return y;
    }
  }

After the quick-fix is applied:


  record Point(int x, int y) {
  }

Enable the Suggest renaming get/is-accessors option to allow renaming getX()/isX() accessors to x() automatically.

Use the When conversion makes a member more accessible options to specify if the conversion may violate class encapsulation:

Use the Suppress conversion if class is annotated by list to exclude classes from conversion when annotated by annotations matching the specified patterns.

This inspection only reports if the language level of the project or module is 16 or higher.

New in 2020.3