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
1
u/OwnBreakfast1114 Sep 11 '26 edited Sep 11 '26
Final fields do have semantics, you can't change the value of them inside the instance of the class you have. You're using a very odd definition of mutability by saying an immutable pointer to a mutable object means that the immutable class holding the immutable pointer is mutable.
Optional, for example, can point to the most mutatey of mutable things, but it's still a value class and not mutable.
this is quite literally the opposite of the what java architects want you to do. Value should be used semantically and let the jvm/javac deal with the performance under the hood. Honestly, there probably needs to be a better definition of identity as I think most people are imagining a different definition than what it actually means in java.
https://www.reddit.com/r/java/comments/1vxwvdu/comment/p5znc19/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button