Record can be converted to class
Reports record classes and suggests converting them to ordinary classes.
This inspection makes it possible to move a Java record to a codebase using an earlier Java version by applying the quick-fix to this record.
Note that the resulting class is not completely equivalent to the original record:
The resulting class no longer extends
java.lang.Record, soinstanceof Recordreturnsfalse.Reflection methods like
Class.isRecord()andClass.getRecordComponents()produce different results.The generated
hashCode()implementation may produce a different result because the formula to calculate recordhashCodeis deliberately not specified.Record serialization mechanism differs from that of an ordinary class. Refer to Java Object Serialization Specification for details.
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.
RecordCanBeClass- 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:
This inspection depends on the Java feature 'Records', which is available since Java 16.
New in 2020.3
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: |