Work with records

Create a record, or convert between classes and records.

Create record

Create a new record by pressing ⌘N (macOS) / Alt+Insert (Windows/Linux) on the Project tool window. From the New Java Class dialog, type the name of the record and select the Record type.

Convert to record

IntelliJ IDEA can identify classes that are data holders and can be converted to records. The class will be highlighted with a warning. Press ⌥⏎ (macOS) / Alt+Enter (Windows/Linux) and IntelliJ IDEA will suggest converting the class to a record.

The fields will be become record components, the constructor and accessors will be removed. If we had equals, hashCode and toString methods on our class, we can optionally remove these and rely on the default record implementation.

Convert from record

If we decide that maybe a record should be a full Java class, we can get IntelliJ IDEA to automatically convert a record into a Java class.

Press ⌥⏎ (macOS) / Alt+Enter (Windows/Linux) on the record name, and IntelliJ IDEA offers a suggestion to convert the record to a class.


Related Resources

Use Pattern Matching for instanceof
Use Pattern Matching for instanceof
Inspections can guide us to use newer Java features.
Go to Next Error
Go to Next Error
Quickly move to the next (or previous) error or warning in the file.
Run inspection
Run inspection
Run inspection by name. For example, run Vulnerable API usage to see where the vulnerable API of external dependencies is used in your code.