Repository navigation
Java 25: Module import declarations (JEP 511) - #103
Merged
Merged
Conversation
Test Results278 tests +2 275 ✅ +2 5s ⏱️ -1s Results for commit 29484f4. ± Comparison against base commit ae4119f. This pull request skips 1 and un-skips 1 tests. |
|
@mperor ⏰ This daily topic is still waiting for your review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What you'll learn
import module M;imports every package exported by moduleMin one declarationMisjava.base, the declaration also pulls in every package exported byjava.baseitselfjava.util.Listvsjava.awt.Listwhen importingjava.desktop)Why it matters
Module imports are a convenient shortcut for exploration and scripting, but mixing them with GUI-ish modules like
java.desktopcan silently shadow commonjava.util/java.iotypes - 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, doesList<String> names = List.of("a");compile?Answer
No - 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