Convert Class to Record

Use inspections to convert classes to Java 16 records.

IntelliJ IDEA can identify classes that are data holders and can be converted to records. The class will be highlighted with a warning (yellow underline) - 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.

Interested in JVM Development?

call to action image

Naturally, you can convert code from a record too!

Learn More


Related Resources

Go to Next Error
Go to Next Error
Quickly move to the next (or previous) error or warning in the file.
Context Actions
Context Actions
There are numerous ways to use Context Actions, let's explore some of them.
Inspections Widget
Inspections Widget
The top-right corner of your editor shows you information about the state of your class at a glance.