valhala larval objects need

46 views Asked by At

I'm watching a video, this one and Remi basically says that value classes must have their fields final. This makes sense, since they will need to be copied to methods, since they don't have references to be passed.

The thing he later says, I don't understand:

final fields can be modified during the execution of a constructor.

and that is why they need to create so-called larval instances.

If an instance has all fields final, it is considered to be safely initialized. This is what Shipilev says in this famous article:

Safe initialization makes all values initialized in constructor visible to all readers that observed the object, regardless of whether the object was safely published or not

So that statement makes me really confused. Is there anything that the VM does different for value classes?

0

There are 0 answers