module-import declaration
Remi Forax
forax at univ-mlv.fr
Fri Feb 23 09:56:08 UTC 2024
Hello,
I've just read the draft of the third version of the implicit class JEP
https://openjdk.org/jeps/8323335
There is a funny paragraph about why there is a need for an import module syntax.
"""
One theme of this JEP is the elegant evolution of simple programs to proper declared classes that can reside in larger codebases; there is no beginners' dialect that must be translated away. In other words, it should be simple to evolve an implicitly declared class to an explicitly declared class. As implicitly declared classes automatically import (as needed) all the accessible classes and interfaces of every exported package in the module java.base, there should be a way to specify this in a traditional compilation unit with explicit class declarations.
To this end, we add a new kind of import declaration: the module-import declaration. It imports (as needed) all the accessible classes and interfaces of every exported package in a given module.
"""
So the thought process is: we do not want a dialect for beginners, but we want an import all, so we are introducing a feature nobody ask for, called module-import so look, this is not a dialect, this is an implicit import-module java.base.
That's a funny !
Taking a step back, I'm not sure that the idea of an "import all" is even a good idea.
It makes the notion that classes are organized in packages hidden so the notion of package documentation (important for beginners) disappear.
Simple SQL examples with an "import java.sql.*" and a reference to a class "Date" to not compile anymore.
We know that import * has a bad behavior when upgrading dependencies, so hidding many import * behind a new import-module syntax means students will have to unlearn import-module later.
regards,
Rémi
More information about the amber-spec-experts
mailing list