[External] : Re: New candidate JEP: 445: Flexible Main Methods and Anonymous Main Classes (Preview)

Ron Pressler ron.pressler at oracle.com
Tue Apr 11 09:46:40 UTC 2023



> On 10 Apr 2023, at 19:25, Glavo <zjx001202 at gmail.com> wrote:
> 
> I like some parts of this proposal, but I disagree with it. I think this proposal is too narrow and limits its usefulness.
> 
> Is the implicit public and static modifiers strange? The interface has worked this way for many years, why is it not acceptable here?

The alternatives section explains why treating members as static is not acceptable. Making them implicitly public makes little sense, as the class is anonymous and so can’t be referenced from other classes anyway. Since it has no declaration it also cannot it implement interfaces.

Note that the body of the anonymous class accepts anything that can be in the body of an anonymous class today, and *its meaning is the same*. There are no new interpretations of syntax here. Interpreting members as implicitly static would be a new interpretation, and it would make it harder to evolve into a named class, where the rules would be different.

Also, note that the flexibility in the main methods is orthogonal to anonymous main classes. The new main methods work even in named classes.


> I think this could be a step towards package-level declarations, whereas the current proposal limits the direction it can go.

The current proposal does not limit that future direction. The reason is that anonymous main classes are singletons, and some future package-level declarations would also be singletons, and when it comes to singletons, there is little difference between static and instance members. 

— Ron


More information about the amber-dev mailing list