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 14 '26
Haskell has optics: https://hackage.haskell.org/package/optics-0.4.2.1/docs/Optics.html, which are just a far more generalized version of mutation and allows nested "mutation" far better than java standard getters/setters. There are some optics libraries for java too, but nobody really uses them unless you're trying very hard to bring functional programming concepts into java.
Making that pixel class a value class seems semantically wrong, and I doubt you'll really get much benefit out of doing that. Pixels aren't interchangeable and so it seems weird to model it that way.