Search code examples
javaheap-memorystack-memoryjava-record

Are Java records stack allocated like C# structs?


Are Java records similar to C# structs? I mean, if they are stack allocated instead of using references like classes, that are allocated on heap.


Solution

  • No. Records are just a simpler way of writing value classes, but are not allocated any differently than normal objects.

    (This is not to say that such types aren't in progress -- they are -- but records are not this feature.)