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

Andrew Evers andrew.evers at gmail.com
Mon Apr 17 14:24:59 UTC 2023


Hi,

1. Understood.

2. I'm not proposing instance initializers, but this has caught two people
now.

I'm proposing that absent a class declaration, the first block _is_ the
main method. You could even argue for the removal of the braces, but that
makes adding methods difficult. This is similar to the shell, python, PHP,
and PL/SQL anonymous blocks.

On Mon, Apr 17, 2023 at 10:14 AM Brian Goetz <brian.goetz at oracle.com> wrote:

>
> > 1. Would it be at all possible to consider a main that returns int?
> > Operating systems that don't support it are free to disregard it, and
> > it feels better than System.exit(). It also allows skipping the idea
> > of void, which is somewhat of a holdover from C.
>
> This is something we've left room to consider in the future, but feels
> like "scope creep" at the present time.
>
> > 2. I have an idea for a slightly different approach to the problem
> > that may solve a few of the problems being proposed, and allows for
> > imports, which would make it more useful for scripting use cases.
>
> AFAICS, the spirit of what you're suggesting is to say that we can treat
> an instance initializer as a "main" method.
>
> I would put this in the category of "clever" ideas, where you're
> repurposing an existing language construct (instance initializers) to
> avoid typing the characters "void main()".   Unfortunately, this fails
> the "on ramp leads gracefully into the highway" test; when the class
> gets complicated enough to need to be a named class, the instance
> initializer sticks out like a sore thumb, because the author didn't want
> an instance initializer, they wanted a main method.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20230417/14df3086/attachment.htm>


More information about the amber-dev mailing list