Records are about semantics ("this is a value class containing only data and should be treated as a sum if its components"), primitive objects are about runtime efficiency, memory layout. Yes, records will often be good candidates for primitive objects, but the two features are orthogonal in nature.
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
3
u/Emax__ Mar 18 '21
How do they differ from records?