Inspectopedia Help

Class can be record class

Reports classes that can be converted record classes.

Record classes focus on modeling immutable data rather than extensible behavior. Automatic implicit implementation of data-driven methods, such as equals() and accessors, helps to reduce boilerplate code.

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

  • The class must be a top-level class and must have no subclasses.

  • All non-static fields in the class must be final.

  • Initializers, generic constructors, and native methods must not be present.

For a full description of record classes, refer to the Java Language Specification.


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 accessor methods option to rename getX()/isX() accessors to x() automatically.

Use the If members become more accessible option to specify what to do when conversion will make members more accessible:

  • Choose Do not suggest conversion option to not convert when members would become more accessible.

  • Choose Show conflicts view option to show the affected members and ask to continue. In batch mode conversion will not be suggested.

  • Choose Convert silently option to increase accessibility silently when needed.

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 depends on the Java feature 'Records' which is available since Java 16.

New in 2020.3

Inspection options

Here you can find the description of settings available for the Class can be record class inspection, and the reference of their default values.

Suggest renaming accessor methods

Default: Selected

If members become more accessible

Do not suggest conversion

Suppress conversion if class is annotated by
  • io.micronaut.*

  • jakarta.*

  • javax.*

  • org.springframework.*

Inspection Details

Available in:

IntelliJ IDEA 2024.2, Qodana for JVM 2024.2,


Java, 242.SNAPSHOT

Last modified: 20 February 2024