Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ not providing option to convert class to record

I have a large set of POJO classes (100+) that I would like to convert to Java records. I would like to automate the process.

I am on Java 18 (Amazon Coretto JDK) and IntelliJ 2022.1.4 (Ultimate Edition): Build #IU-221.6008.13, built on July 18, 2022

coretto-18 is configured to be module's default VM.

I followed the IntelliJ documentation (https://www.jetbrains.com/idea/guide/tips/convert-to-record/), but the Context Actions on won't show the option "Convert to a record" (expected).

enter image description here

like image 654
mitchkman Avatar asked Dec 30 '25 07:12

mitchkman


2 Answers

Records are immutable - all their fields are final. "Convert to a record" in the Context Actions doesn't show up because your class isn't equivalent to a record. To get it, make all fields final or change @Data to its immutable version @Value.

like image 50
Prectron Avatar answered Dec 31 '25 21:12

Prectron


I went to Inspections -> Class Can Be A Record

Removed javax.* from Suppress conversion if class is annotated by

like image 22
Sam Barnum Avatar answered Dec 31 '25 20:12

Sam Barnum