JEL 477 Issue

Remi Forax forax at univ-mlv.fr
Tue Jul 30 16:57:15 UTC 2024


> From: "Jaikiran Pai" <jai.forums2013 at gmail.com>
> To: "jdk-dev" <jdk-dev at openjdk.org>
> Sent: Tuesday, July 30, 2024 5:43:34 PM
> Subject: Re: JEL 477 Issue

> > import module java.base;

> > main() {

> > println("Moose");

> >}

> It appears that you are missing a "void" return type before the main() method
> name. As noted in the JEP-477, it should be:

> import module java.base;
> void main() {
> println("Moose");
> }
that said, if we want beginners to be able to use that syntax, the error message should be changed because the current message is misleading and not very helpfull (javac should recognize "main" and have a tailored error message). 

@Ken, you do not need to import module java.base, it's done by default and --source 23 is not needed anymore since 23. 

> -Jaikiran
regards, 
Rémi 

> On 30/07/24 9:05 pm, [ mailto:omniprof at gmail.com | omniprof at gmail.com ] wrote:

>> I apologize for posting what is likely a trivial question that may be
>> inappropriate for this list but I cannot find anywhere in my searches to
>> explain what is going wrong. Simply put JEP 477 does not work in the
>> pre-release version of Java 23 on a Windows 11 PC. There is a lot written that
>> all show a similar example.

>> >> Here is the program

>> import module java.base;

>> main() {

>> println("Moose");

>> }

>> >> Here is the version of Java I am running

>> C:\dev\Onramptesting\OnRamptest\src>java --version

>> openjdk 23-ea 2024-09-17

>> OpenJDK Runtime Environment (build 23-ea+34-2361)

>> OpenJDK 64-Bit Server VM (build 23-ea+34-2361, mixed mode, sharing)

>>>> Here I run the code with all the required switches. The errors are the same with
>> >> or without Xlint

>> C:\dev\Onramptesting\OnRamptest\src>javac --enable-preview --source 23
>> -Xlint:preview Main.java

>> Main.java:1: warning: [preview] module imports are a preview feature and may be
>> removed in a future release.

>> import module java.base;

>> ^

>> Main.java:3: error: class, interface, enum, or record expected

>> main() {

>> ^

>> Main.java:5: error: class, interface, enum, or record expected

>> }

>> ^

>> 2 errors

>> 1 warning

>> Note that I get the same results for –source 23 and –release 23

>> Trying single file:

>> java –enable-preview Main.java

>> does not work as well.

>> Same result using Console or PowerShell in Windows.

>> What am I doing wrong?

>> Ken Fogel

>> [ mailto:omniprof at gmail.com | omniprof at gmail.com ]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jdk-dev/attachments/20240730/7b0ff6b1/attachment-0001.htm>


More information about the jdk-dev mailing list