Class can be a record
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:
A class must contain no inheritors and must be a top-level class.
All the non-static fields in class must be final.
Class must contain no instance initializers, generic constructors, nor native methods.
To get a full list of the restrictions, refer to the Oracle documentation.
Example:
After the quick-fix is applied:
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:
Choose Do not suggest conversion option to never violate class encapsulation
Choose Show affected members in conflicts view option to apply conversion with notification about encapsulation violation issues
Choose Convert silently option to apply conversion silently whether encapsulation violation issues exist or not
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
Inspection options
Option | Type | Default |
---|---|---|
Suggest renaming get/is-accessors | Checkbox | true |
If members become more accessible | Dropdown | Do not suggest conversion |
Suppress conversion if class is annotated by | StringList | [io.micronaut.*, jakarta.*, javax.*, org.springframework.*] |
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |