New candidate JEP: 477: Implicitly Declared Classes and Instance Main Methods (Third Preview)
Remi Forax
forax at univ-mlv.fr
Wed May 8 09:59:44 UTC 2024
> From: "Olexandr Rotan" <rotanolexandr842 at gmail.com>
> To: "amber-dev" <amber-dev at openjdk.org>
> Cc: "Gavin Bierman" <gavin.bierman at oracle.com>, "Ron Pressler"
> <ron.pressler at oracle.com>, "jdk-dev" <jdk-dev at openjdk.org>
> Sent: Tuesday, May 7, 2024 9:06:28 PM
> Subject: Re: New candidate JEP: 477: Implicitly Declared Classes and Instance
> Main Methods (Third Preview)
> 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.
We (the amber EG) already rejected that proposal for several reasons. The main reason for me is that the semantics of a field and the semantics of a local variable are very different and here you are trying to promote local variables to fields.
> Best regards.
regards,
Rémi
> On Tue, May 7, 2024 at 8:55 PM Mark Reinhold < [ mailto:mark.reinhold at oracle.com
> | mark.reinhold at oracle.com ] > wrote:
>> [ https://openjdk.org/jeps/477 | 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/jdk-dev/attachments/20240508/31d5be3f/attachment.htm>
More information about the jdk-dev
mailing list