Record copies/mutating

Jordan Zimmerman jordan at jordanzimmerman.com
Thu Sep 5 22:38:40 UTC 2019


(moved from an inappropriate reply on the draft spec)

Records (and the chain of features from switch expressions to pattern matching and deconstruction) will be as fundamental a change as Java 8's lambdas were. When the chain of features is complete, Java will likely have the best of breed version of this style of coding - except for one thing. Every other language I've surveyed has some method for mutating data carrier values. Now, I think it's the correct decision to make record fields final. But, why can't there be mutators (or a copy method) that returns a new record with the desired changes? I've already read discussion on various blogs/boards about this missing functionality in records. What this implies to me is that a) people want it dearly and b) when people want things various home grown solutions will be written. We can all think of many ways of solving this problem (each field has a corresponding mutator with the same name that returns a new record, a single copy method, etc.). Why not prevent confusion, disappointment and a plethora of incompatible mutating libraries now while this feature is still being developed? So, my plea is to please add some well defined way of creating modified copies of records so that they can be used in entity frameworks and the like.

-Jordan


More information about the amber-spec-observers mailing list