JDK-8328935 : Implement Module Imports
  • Type: CSR
  • Component: tools
  • Sub-Component: javac
  • Priority: P4
  • Status: Provisional
  • Resolution: Unresolved
  • Fix Versions: 23
  • Submitted: 2024-03-25
  • Updated: 2024-04-19
Related Reports
CSR :  
Relates :  
Description
Summary
-------

Enhance the Java language with a new types of imports - an import that can import all exported packages from a module. The main goal is to aid beginner programers.

Problem
-------

In order to write a simple program, beginner programmers must often import classes from multiple packages - like `java.io` and `java.util`. This is distracting them from their goal at hand, and creates obstacles in learning Java.

Solution
--------

We propose that a new type of imports is added to the Java language. This new import would import all the packages exported from a given module.

For example:

    import module M;

Should import all packages exported to the current module from `M` and its transitive dependencies as if they were imported using the type-on-demand imports for the respective packages.

Some relevant adjustments to the Trees API and JShell API are needed as well.

Specification
-------------

The draft JLS changes is attached as a pdf.

The draft specdiff for the API changes is attached as specdiff.preliminary.00.zip, and also available for convenience here:
https://cr.openjdk.org/~jlahoda/8328481/specdiff.preliminary.00/overview-summary.html

This is a preview language feature.

Both these drafts are subject of change until the CSR is finalized.

Comments
[~darcy] Thanks. I updated the spec to discuss package-info.java files. (See example 7.5.5-1.) Yes to the redundant question. Yes to the preview classes and interfaces being imported.
18-04-2024

Moving to Provisional, not Approved. The specification changes don't look to including an explicit example discussing package-info files; I think that would be worth mentioning. Also, presumably in import module java.base; import java.until.*; the "import java.until.*" is redundant and ignored. Also presumably, preview classes and interfaces are also imported?
18-04-2024