[External] : Re: Minor improvement to anonymous classes
Brian Goetz
brian.goetz at oracle.com
Sat Jul 31 19:46:22 UTC 2021
> so when you use an anonymous class, the lifetime of the enclosing this is extended for no good reason.
> The usual issue it to have a code that relies on the finalizer to close a system resource (which is not a good idea) that fails to close the resource because the is captured by the anonymous class. Lambdas do not have this weird behavior.
>
> We have discussed about allowing static in front of a local class but there is no way to ask for a static anonymous class.
We've already laid the groundwork for that; the recent changes to allow
for local interfaces/records/enums included some spec wording for static
local members, even though you can't say `static` in all these places.
I'd like to address this as part of a more comprehensive
scoping-alignment; the inner-class thing seems mostly a separate (and
small) feature.
> and i would prefer to keep that syntax available if at some point in
> the future we decide to allow classes (or perhaps just record) to be
> initialized in a literal way.
Agree, I think the "return on syntax" here is limited.
More information about the amber-spec-experts
mailing list