Skip to content

Java 25: Module import declarations (JEP 511) - #103

Merged
mperor merged 1 commit into
masterfrom
DAILY/90-module-import-declarations
Oct 27, 2026
Merged

mperor merged 1 commit into
masterfrom
DAILY/90-module-import-declarations

Conversation

@mperor

@mperor mperor commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

What you'll learn

  • import module M; imports every package exported by module M in one declaration
  • unless M is java.base, the declaration also pulls in every package exported by java.base itself
  • that extra rule can make a bare type name ambiguous (java.util.List vs java.awt.List when importing java.desktop)
  • a regular single-type import still wins over a module import and resolves the ambiguity

Why it matters

Module imports are a convenient shortcut for exploration and scripting, but mixing them with GUI-ish modules like java.desktop can silently shadow common java.util/java.io types - knowing the resolution order avoids confusing compile errors.

Read more

JEP 511: Module Import Declarations

Quiz

Given import module java.desktop; and no other import, does List<String> names = List.of("a"); compile?

AnswerNo - it fails with "reference to List is ambiguous" because `java.desktop` exports `java.awt.List` and, since it isn't `java.base`, the declaration also imports `java.base`'s packages, which include `java.util.List`. Adding `import java.util.List;` resolves it, since a single-type import takes precedence over a module import.

Closes #90

@mperor mperor added the daily Queued for the daily learning PR label Oct 26, 2026
@github-actions

Copy link
Copy Markdown

Test Results

278 tests  +2   275 ✅ +2   5s ⏱️ -1s
 80 suites ±0     3 💤 ±0 
 80 files   ±0     0 ❌ ±0 

Results for commit 29484f4. ± Comparison against base commit ae4119f.

This pull request skips 1 and un-skips 1 tests.
pl.mperor.lab.java.design.pattern.creational.singleton.SingletonTest ‑ testLazyInitialized()
pl.mperor.lab.java.design.pattern.creational.singleton.SingletonTest ‑ testSerializationSafe()

@github-actions

Copy link
Copy Markdown

@mperor ⏰ This daily topic is still waiting for your review.

@mperor
mperor merged commit b42879b into master Oct 27, 2026
2 checks passed
@mperor
mperor deleted the DAILY/90-module-import-declarations branch October 27, 2026 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

daily Queued for the daily learning PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Java 25: Module import declarations (JEP 511)

2 participants