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

Ron Pressler ron.pressler at oracle.com
Sun May 12 18:46:50 UTC 2024



> On 7 May 2024, at 20:06, Olexandr Rotan <rotanolexandr842 at gmail.com> wrote:
> 
> 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).

As is usually the case, the challenge here is not in finding a technical solution to a problem but finding the right problem to solve.

While we started out exploring the problem of making it easy to write a basic program, we later realised that a better problem to solve is how to write a basic program that can easily evolve, hence the “no new mode/dialect” requirement in the JEP. In other words, the requirement is that any code unit in an implicit class could be copied over to an explicit class without changing its semantics. Consequently, all you need to do to “upgrade” from an implicit class to an explicit class is add a class declaration (and a couple of imports). The top-level code approach doesn’t satisfy this requirement.

This is what we mean when we say “onramp”: there are two requirements for an onramp — it should be easy to get on and it should make it easy to merge onto the highway.

Since all the onramp approach cost us here (compared to top-level code) is adding a main method declaration, it’s a small price to pay to solve what we think is the more appropriate problem to solve.

— Ron


More information about the jdk-dev mailing list