r/java • u/joemwangi • Mar 17 '26
Updates to Derived Record Creation - amber-spec-experts
https://mail.openjdk.org/archives/list/amber-spec-experts@openjdk.org/thread/QVALXGP2BRN27ISPNJTA3HEKEIMKLWLG/Interesting discussion on the evolution of derived record creation (“withers”). The proposal seems to be shifting from mutation like blocks to a more explicit reconstruction model using obj.new(...), aligning more closely with constructor semantics and pattern matching.
45
Upvotes
View all comments
Show parent comment
0
u/davidalayachew Mar 17 '26
I contest that.
Why do we have local blocks at all, if not to accomplish exactly what I am doing? Where exactly the line is between "it's fine to be in the local scope" vs "it should be in its own scope" is different for everyone. But I still assert that there exists a breaking point where a scope is doing too much.
And sure, you can break it out into a method, but there is the exact same threshold for methods, where you can simply have too many methods in your class or it's various helper tasks. Furthermore, a method encourages reuse, which may or may not be relevant for the task on hand.
Hence why we have the ability to add arbitrary blocks, should we want to. There are sometimes where we just need a new scope, without the other features of a method.
So no, I assert that there are many situations where a local block is simply the clear, correct tool for the task at hand.
But back to the point -- because I believe that there are situations where developers should be encouraged by the language to use local blocks, I therefore believe that the "reconstruction" proposal is slightly inferior to the "withers" proposal, in that it does not facilitate it in a situation where I feel it really really should. Object construction is where it makes the most sense to have a local block.