Skip to content

Add Module Import #52

@Flashky

Description

@Flashky

JDK 24 feature (preview)

Currently in JDK 23 preview, it is possible to automatically import all most common java classes by adding:

import module java.base;

Before this feature, importing the a List and an ArrayList would require two imports:

import java.util.List;
import java.util.ArrayList;
//...
List<String> myList = new ArrayList<>();

Or just import java.util.*, but the compiler would warn you about having a not needed import.

With this feature:

import module java.base;
//...
List<String> myList = new ArrayList<>();

If there is no List at the code, there won't be any import warnings.

IntelliJ IDEA configuration

IntelliJ can be configured at Settings / Editor / File and Code Templates to include by default the import module java.base statement at newly created classes:

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};

#end
import module java.base;

#parse("File Header.java")
public class ${NAME} {
}

That way, newly created classes can start using collection classes right away from start.

More information

https://foojay.io/today/java-23-has-arrived-and-it-brings-a-truckload-of-changes/
https://openjdk.org/jeps/476

Metadata

Metadata

Assignees

No one assigned

    Labels

    new jdk featuresModifications of code related to new JDK features

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions