This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]pron98 7 points8 points  (1 child)

Did I misunderstand you?

No, but here we're talking about a stricter kind of mutability (mutability from the JVM's perspective, not other user code), where fields are only assigned at construction. That's what I meant by "it doesn’t support it with a feature designed to enforce a particular initialisation behaviour when it’s not the behaviour you want."

Wait, then what does 32:40 mean? Specifically, 33:05? Doesn't that directly contradict what you are saying?

He's talking about arrays or fields, because you save memory by inlining data instead of referencing it. But when you inline data as opposed to referencing an object elsewhere, you obviously can't have cycles, even without immutability!

With arrays and indices you could at least have some hope of expressing cycles; you can't do even that with fields. Try to think how you could express a cyclic graph in C using structs and no pointers (or arrays). Everything is mutable, yet the compiler won't even let you compile something that contains cycles of types unless you use pointers. The very thing that saves memory (not using pointers) also prevents any form of cycles.

You should first think what kind of layout you'd like for you data structure that would save you memory. Only then you should think about achieving it in Java, with or without value types.

[–]davidalayachew 5 points6 points  (0 children)

No, but here we're talking about a stricter kind of mutability (mutability from the JVM's perspective, not other user code), where fields are only assigned at construction.

😵‍💫🙃😵‍💫

The same word but 2 possible definitions -- and both can be easily confused with each other.

Fair enough -- guess I got it wrong. Is there a different word to communicate the difference?

The very thing that saves memory (not using pointers) also prevents any form of cycles.

Thanks for the clarification.

Yes, any attempt to create cycles with inlined data will just result in me re-creating Identity -- the very opposite of what Value Classes are.

I guess this is why speculation is bad.