[External] : Re: [module-imports] Importing java.se?

Alex Buckley alex.buckley at oracle.com
Wed Jul 17 18:08:33 UTC 2024


On 7/17/2024 12:32 AM, Tagir Valeev wrote:
> In my sample, implicit class is not used. I think, at some point, 
> beginners move away from implicit classes, and the question still
> remains, whether it's a reasonable idea to use `import module java.se`,
> or not. I find it strange that to import the whole Java SE API, one
> need to add two explicit imports (java.se and java.base) when not
> using implicit class.

There are two problems:

1. A compilation unit in the unnamed module -- whether it has an 
implicitly declared class or an explicitly declared class -- cannot 
`import module java.se` or any other aggregator module.

2. A compilation unit in a named module (which implies an explicitly 
declared class) can `import module java.se` (provided of course that the 
named module `requires java.se`) ... but `import module java.se` does 
not have the effect of performing `import module java.base`, which needs 
to be done separately.

Fixing #1 is hard because it requires a platform-wide change to the 
default set of root modules for the unnamed module.

Fixing #2 so that `import module java.se` brings in java.base is also 
hard. A proposal is to allow `requires transitive java.base` so that the 
core modules of a framework, which never say `requires java.base` today, 
would say `requires transitive java.base` tomorrow. I don't like this 
proposal because every module in existence reads java.base already. It's 
a declaration-site approach that requires perfect awareness by module 
authors; we could achieve the same thing more straightforwardly at the 
use site, by decreeing that any use of `import module ...` implicitly 
performs `import module java.base` too.

We'll discuss more when people get back from vacation.

Alex


More information about the amber-spec-experts mailing list