New candidate JEP: 477: Implicitly Declared Classes and Instance Main Methods (Third Preview)

Olexandr Rotan rotanolexandr842 at gmail.com
Tue May 7 19:06:28 UTC 2024


Could it be possible to not oblige users to create a void main() method? It
would be great if a person that sees java for the first time has the option
to write code in plain document without any additional method declarations
(even method concept is kind of hard for a complete newbie).

I see this accomplishable without any changes to Java language in a
following way:

1. Every variable declaration is elevated to the top-level scope of
implicitly declared class without initialization. Initialization will be
performed later. There could possibly be a problem with var keyword, but if
desugaring is performed after attribution, type idents could be explicitly
added in the "trans" phase.
2. Every other top-level statement that is not a method or class
declaration in a document is wrapped in the anonymous code block of an
implicitly declared class. In this scope any "this" refs should be
forbidden as well as return statements.
3. Every top-level class and method declaration is elevated to a top-level
declaration inside an implicitly declared class. If a class is not static,
any instance creation of such classes after desugaring should be created as
this.new X(). Constructor declarations for implicitly declared class must
be forbidden.
4. Main method is implicitly generated. It creates a new instance of
implicitly declared class. This will trigger run of code in anonymous code
blocks.

I understand that these changes could dramatically change current flow in
the implementation, but this way I think this feature could be more
friendly towards new users by allowing them to write their first hello
world program without having to learn concepts of methods and possibly
confusing concepts of void type.

Best regards.

On Tue, May 7, 2024 at 8:55 PM Mark Reinhold <mark.reinhold at oracle.com>
wrote:

> https://openjdk.org/jeps/477
>
>   Summary: Evolve the Java programming language so that beginners can
>   write their first programs without needing to understand language
>   features designed for large programs. Far from using a separate
>   dialect of the language, beginners can write streamlined declarations
>   for single-class programs and then seamlessly expand their programs to
>   use more advanced features as their skills grow. Experienced developers
>   can likewise enjoy writing small programs succinctly, without the need
>   for constructs intended for programming in the large. This is a preview
>   language feature.
>
> - Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20240507/5cc48594/attachment.htm>


More information about the amber-dev mailing list