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 Record
returnsfalse
.Reflection methods like
Class.isRecord()
andClass.getRecordComponents()
produce different results.The generated
hashCode()
implementation may produce a different result because the formula to calculate recordhashCode
is deliberately not specified.Record serialization mechanism differs from that of an ordinary class. Refer to Java Object Serialization Specification for details.
Example:
After the quick-fix is applied:
This inspection only reports if the language level of the project or module is 16 or higher.
New in 2020.3
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |