r/java • u/davidalayachew • Jul 16 '26
Identifying JDK value class candidates
https://mail.openjdk.org/archives/list/core-libs-dev@openjdk.org/thread/Y72NRXM7KYBX43OKYBQMVKOZDWKG4MHS/
52
Upvotes
View all comments
Show parent comment
2
u/davidalayachew Jul 16 '26
But now you have changed the API, which makes it backwards-incompatible. That's a faux pas in the Java community without justifiable reason.
Remember, the method signature of Map.Entry#setValue is as follows.
Which is to say -- it sets the new value, and returns the old. So, not only are you changing the API, but you are also removing pre-existing functionality. With your change, we can no longer return the old value, which would upset many users of this API.
Now, by all means, we could certainly add some sort of
transformfunction that does what you say, but that still would not solve our current problem -- thatMap.Entrydoes mutation. At best, we could have implementing subclasses that are value classes, and throwUnsupportedOperationException, but that's the best we can do. And even that is somewhat unsatisfying.