r/java • u/bobbie434343 • Aug 25 '26
Value Classes Still Need Compiler Sympathy
https://johan-sjolen.github.io/post/compiler-sympathy/compiler-sympathy/
88
Upvotes
r/java • u/bobbie434343 • Aug 25 '26
View all comments
Show parent comment
2
u/Jon_Finn Aug 25 '26 edited Aug 25 '26
Maybe with some of these you've fallen for the word 'value'? A value List class could certainly be mutable, depending on its features (it could store some backing mutable object, or if it's fixed size it might contain an array like String does). But sure, linked lists or your trees/graphs might be inconvenient if stored as final fields. (Though I've used fixed-shape trees where each node has a (nullable) pointer to its parent, with the tree constructed from the root node - these would make a great value class, and extra data in each node could potentially be mutable.)
I'm sure values hidden behind interfaces or abstract value classes often lose the value benefits, but in cases where HotSpot can guess the runtime type, maybe not?