New candidate JEP: 445: Flexible Main Methods and Anonymous Main Classes (Preview)

Red IO redio.development at gmail.com
Tue Apr 18 04:48:15 UTC 2023


I think it won't be a problem to allow imports in an anonymous class body
as the "import xyz;" syntax isn't used by anything that could make this
ambiguous.

For the main method I think we have 2 valid paths to choose here.

1. The whole file is main and we allow methods in methods meaning that the
files content is practically a static main method in an anonymous class.
(C# style)

2. We keep the main method as a method static or non static with return
type (void, int) "main" parameters (nothing or args) and the main block.
(currently proposed)

Personally I prefer the later as it still provides a visual marker for the
entry point and prevents confusion when for example a beginner switches
from anonymous to a named class and wonders why he can't write statements
in the class body. The difference between class scope and method scope is
important to understand.


A bit of topic but I would love to see methods in methods and statics in
methods allowed regardless of the "main" topic as they are technically
possible (using an inner class in the method) but have huge syntactic
overhead due to the unnecessary inner class.

Great regards
RedIODev



On Tue, Apr 18, 2023, 02:23 Andrew Evers <andrew.evers at gmail.com> wrote:

> > > I think it would behoove the group to find a way for import statements
> to be allowed.
> >
> > Imports are allowed. Can you say which part of the JEP led you to
> believe they aren’t? Maybe we need to clarify something.
>
> The JEPs mention import four times. The first implies it might be
> possible, the second in the current launch protocol, and the other two
> prefaced by "excluding".
>
> If there was an example that included an import statement, it would help a
> lot.
>
>
> On Mon, Apr 17, 2023 at 7:42 PM Ron Pressler <ron.pressler at oracle.com>
> wrote:
>
>>
>>
>> > On 17 Apr 2023, at 16:34, Andrew Evers <andrew.evers at gmail.com> wrote:
>> >
>> >
>> > I would say that it retains the signature of main() exactly as it has
>> been for 20+ years, and allows an additional stage of using imports prior
>> to moving to the full class syntax. It's at most 13 bytes shorter, hardly
>> noticeable.
>>
>> JEP 445 also support imports and also retains the signature of main. It
>> just accepts a few more signatures, and also allows an instance main to
>> process command-line arguments.
>>
>> >
>> > I think it would behoove the group to find a way for import statements
>> to be allowed.
>>
>> Imports are allowed. Can you say which part of the JEP led you to believe
>> they aren’t? Maybe we need to clarify something.
>>
>> — Ron
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20230418/fe3ec141/attachment-0001.htm>


More information about the amber-dev mailing list