Updated document on data classes and sealed types

Guy Steele guy.steele at oracle.com
Thu Mar 7 22:18:39 UTC 2019

> On Mar 7, 2019, at 4:52 PM, Kevin Bourrillion <kevinb at google.com> wrote:
> On Thu, Mar 7, 2019 at 12:47 PM Brian Goetz <brian.goetz at oracle.com <mailto:brian.goetz at oracle.com>> wrote:
> Normalization can happen on single arguments or multiple:
>      record Person(String name) { 
>           public Person {
>                name = name.toUpperCase();
>           }
>      }
> (Note that I’m mutating the parameter, which will then get written to the field.)
> I'm a bit relieved to hear this. The document seemed to imply that you would assign to the field, then later the remaining fields that weren't DA would be set from the remaining parameters. I think parameter reassignment is superior because there are never two versions of the data in scope at the same time. (I think the argument against parameter reassignment is mainly that it's heresy.)

I see no heresy in assigning to a non-final variable.

On the other hand, I’m a great believer in adding `final` to my method parameters, at least when there might be any doubt.

Anyone who complains that “Duh, parameters should *always* be final, why isn’t that the default?” will find me replying “Duh, local variables should *almost always* be final, why isn’t that the default?”



More information about the amber-spec-observers mailing list