I recently discovered Java records, and it was amazing to learn about their existence and purpose.
However, I began to wonder if they are essentially just classes behind the scenes.
Does this mean that during compilation, they get converted into an explicit class with final private fields, a public constructor, and the necessary getters?
Under the hood it will still create a class (that's derived from
java.lang.Record
).You can try it out yourself:
When you compile this with
javac test.java
and disassemble it again withjavap Test
you'll get this code: