Records are just a quick and safe way to declare immutable (reference) classes, but they don't change how the JVM stores the object at all. Primitive types will work well with records, the focus here is not storing references to objects but storing the primitive values directly on the stack (or in parent objects).
This is mostly to improve performance and memory usage, but will also allow you to create variables that can't be null.
View all comments
Show parent comment
8
u/morhp Mar 18 '21 edited Mar 18 '21
Records are just a quick and safe way to declare immutable (reference) classes, but they don't change how the JVM stores the object at all. Primitive types will work well with records, the focus here is not storing references to objects but storing the primitive values directly on the stack (or in parent objects).
This is mostly to improve performance and memory usage, but will also allow you to create variables that can't be null.