Jep 468: What about 'new' syntax?
Brian Goetz
brian.goetz at oracle.com
Wed Nov 20 13:18:16 UTC 2024
> Hello. Just a side note: AFAIK "new", by spec, guarantees that new
> instance of object is returned
>
Historically this is true. However, when Valhalla gives us value types,
the "new"-ness of a new value object will be indistinguishable from an
old object. So I would advise against taking this "new means new"
dictum too literally.
> , so it can potentially affect implementation requirements for
> compilers, forcing them to copy records even if with expression block
> is empty, i.e.
>
> var b = new a with {}
>
> Unless there is a exception for such syntax, new will mandate that b
> != a (by reference)
>
... unless a and b are value objects, in which case == compares their
state, not their identity (because they have none.)
More information about the amber-dev
mailing list