Observation: Module imports and java.io.IO

Gavin Bierman gavin.bierman at oracle.com
Thu May 16 14:24:15 UTC 2024


Hi Eirik,

Thanks for your email.

I totally get where you are coming from but I really don’t think anyone would want “import module” to have the additional semantics of importing all the static members.

That then leads us to “doing something special” which, depending on who gets that special behaviour, is either very non-Java in its feel, or ends up defining a “beginner’s dialect” which is an explicit non-goal of the JEP.

Hope that helps,
Gavin

PS: Actually in the section on “growing a program” the static import could just be “import static java.io<http://java.io>.IO.println;”, which at least removes the wildcard.

On 14 May 2024, at 17:26, Eirik Bjørsnøs <eirbjo at gmail.com> wrote:

Hi,

JEP-477 includes the section "Growing a program", showing how an implicit class can be grown into an ordinary class by wrapping it in a class declaration and adding the necessary (no longer implicit) imports:

import static java.io.IO.*;
import java.util.List;          // alternatively: import module java.base;

The module import of java.base (from JEP-476) strikes me as very elegant in this context in that it provides the learning programmer access to Java's basic APIs in a single import. "Give me the basic java stuff", thanks!

The sad thing is that the "basic java stuff" does not seem to include the static methods in java.io.IO<http://java.io.io/>. So the learning programmer still needs to add "import static java.io.IO.*". This doubles the number of imports needed, but worse, it introduces the concepts of static imports and wildcard imports!

I was thinking it would be really nice if "import module java.base" somehow also included the new IO methods.

Has this interaction between JEP-177 and JEP-476 been discussed in the expert group?

Thanks,
Eirik.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20240516/8b7dc976/attachment-0001.htm>


More information about the amber-dev mailing list