Paul Krill
Editor at Large

Java proposal would streamline module package imports

news
Apr 19, 20242 mins

Allowing entire modules to be imported all at once would eliminate tedious typing and simplify the reuse of modular libraries in Java.

Java would be enhanced with the ability to succinctly import all packages exported by a module, under a proposal floating in the Java community. The plan would simplify the use of modular libraries in Java.

The preview language feature for Java SE (Standard Edition), called Module Import Declarations, has been filed as a JDK Enhancement Proposal (JEP) in the OpenJDK community.

Goals of the plan include simplifying the reuse of modular libraries by allowing entire modules to be imported at once, avoiding the noise of multiple type-import-on-demand declarations when using diverse parts of the API exported by a module, and allowing beginners to more easily use third-party libraries and fundamental Java classes without having to learn where they are located in a package hierarchy, the proposal states.

It is not a goal to require developers who use the module import feature to modularize their own code. The feature does not require the importing code to be in a module.

Motivating the proposal is the desire to dramatically reduce the number of import declarations that Java programmers need to write. Although classes and interfaces in the java.lang package, such as Object, String, and Comparable, are automatically imported by the Java compiler on demand, other essential classes and interfaces, such as List, Map, Stream, and Path, are not. As a result, developers must write numerous import declarations at the beginning of every source file.

The ability to import at the level of modules would be especially helpful when APIs in one module have a close relationship with APIs in another module. Automatically importing on demand from transitive dependencies would be a further convenience when prototyping and exploring, the proposal says.

Created in August 2023 and updated April 18, the proposal does not yet target the capability for a specific version of Java. The first possibility would be JDK 23, due in September.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author