Class can be record class
Reports classes that can be converted to 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 restrictions:
The class 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.
Locating this inspection
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
ClassCanBeRecord- Via Settings dialog
Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.
Example:
After the quick-fix is applied:
Enable the Suggest renaming accessor methods option to rename getX()/isX() accessors to x() automatically.
Use the Don't report if members become more accessible option to exclude classes whose members' accessibility would be weakened by conversion. Quick-fix will stay available as an intention, and triggering it will show the affected members and ask for confirmation. In batch mode conversion will not be suggested.
Use the Suppress conversion if the 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.
Inspection ID: ClassCanBeRecord
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
Option ID:
suggestAccessorsRenamingDefault value:
Selected- Don't report if members become more accessible
Option ID:
noHighlightingFixAvailableDefault value:
Selected- Suppress conversion if the class is annotated by
Option ID:
myIgnoredAnnotationsDefault value:
[io.micronaut.*, jakarta.*, javax.*, org.springframework.*]
Suppressing Inspection
You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:
More detailed instructions as well as other ways and options that you have can be found in the product documentation:
Inspection Details | |
|---|---|
By default bundled with: |