Add jep511 module: module import declarations on JDK 25 and 27

Runnable sources, deliberate compile failures, three small modules and nine captured transcripts for import module (JEP 511).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TF9JWFvJSNm6HVzswzZU5a
This commit is contained in:
Claude
2026-09-24 10:57:57 +00:00
parent 2ebea58d39
commit 385cc25233
44 changed files with 715 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
import module java.sql;
void main() {
Date d = new Date(0L); // implicit java.base (java.util.Date) vs explicit java.sql (java.sql.Date)
IO.println(d.getClass().getName());
}
+3
View File
@@ -0,0 +1,3 @@
void main() {
IO.println(List.of("no imports at all"));
}
+6
View File
@@ -0,0 +1,6 @@
import module java.sql;
void main() {
var l = List.of("java.base came implicitly"); // no import module java.base written
IO.println(l + " " + Connection.TRANSACTION_NONE); // java.sql from the explicit import
}
+10
View File
@@ -0,0 +1,10 @@
import module java.base;
import module java.base;
import java.util.List;
import java.util.List;
public class DuplicateImports {
public static void main(String[] args) {
System.out.println(List.of("dups are fine"));
}
}
+12
View File
@@ -0,0 +1,12 @@
import module java.base;
import module java.sql;
import java.util.Date; // a single-type import wins over both module imports
public class FixedDate {
public static void main(String[] args) {
Date d = new Date(0L);
System.out.println(d.getClass().getName());
java.sql.Date s = new java.sql.Date(0L); // the other one is still reachable by its full name
System.out.println(s.getClass().getName());
}
}
+9
View File
@@ -0,0 +1,9 @@
package demo.mod;
import module java.base;
public class InPackage {
public static void main(String[] args) {
System.out.println(List.of(1, 2, 3) + " from package " + InPackage.class.getPackageName());
}
}
+10
View File
@@ -0,0 +1,10 @@
import module java.se;
import java.util.List; // java.se brings in java.desktop, whose java.awt.List clashes with java.util.List
public class JavaSe {
public static void main(String[] args) {
List<String> l = List.of("a"); // java.base
Logger lg = Logger.getLogger("x"); // java.logging
System.out.println(l + " " + lg.getName() + " " + Connection.TRANSACTION_NONE); // java.sql
}
}
+11
View File
@@ -0,0 +1,11 @@
import module java.base;
public class NewWay {
public static void main(String[] args) {
List<String> words = List.of("apple", "avocado", "banana", "blueberry", "cherry");
Map<Character, List<String>> byInitial = words.stream()
.collect(Collectors.groupingBy(w -> w.charAt(0)));
System.out.println(byInitial);
System.out.println(Path.of("a", "b", "c.txt") + " on " + LocalDate.of(2026, 9, 15));
}
}
+17
View File
@@ -0,0 +1,17 @@
import java.nio.file.Path;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class OldWay {
public static void main(String[] args) {
List<String> words = List.of("apple", "avocado", "banana", "blueberry", "cherry");
Map<Character, List<String>> byInitial = words.stream()
.collect(Collectors.groupingBy(w -> w.charAt(0)));
System.out.println(byInitial);
System.out.println(Path.of("a", "b", "c.txt") + " on " + LocalDate.of(2026, 9, 15));
}
}
+12
View File
@@ -0,0 +1,12 @@
import module java.base;
class Date { // a class in this file's own package
public String toString() { return "my own Date"; }
}
public class SamePackageWins {
public static void main(String[] args) {
System.out.println(new Date()); // which Date?
System.out.println(new java.util.Date(0L).getClass().getName());
}
}
+6
View File
@@ -0,0 +1,6 @@
import module java.base;
void main() {
var now = LocalDate.of(2026, 9, 15);
IO.println(Stream.of("a", "b", "c").collect(Collectors.joining("-")) + " " + now);
}
+9
View File
@@ -0,0 +1,9 @@
import java.util.*;
import module java.sql;
public class StarImportWins {
public static void main(String[] args) {
Date d = new Date(0L);
System.out.println(d.getClass().getName());
}
}
+9
View File
@@ -0,0 +1,9 @@
import java.sql.*;
import module java.base;
public class StarImportWinsSql {
public static void main(String[] args) {
Date d = new Date(0L);
System.out.println(d.getClass().getName());
}
}
+5
View File
@@ -0,0 +1,5 @@
import module acme.text;
void main() {
IO.println(Slug.of("A script using a library module"));
}
+15
View File
@@ -0,0 +1,15 @@
import module java.base;
import module java.sql;
public class Transitive {
public static void main(String[] args) {
// java.sql declares "requires transitive" java.logging, java.xml and java.transaction.xa,
// so importing java.sql also imports their exported packages.
Logger log = Logger.getLogger("demo"); // java.util.logging (java.logging)
System.out.println(log.getName());
System.out.println(XAResource.TMNOFLAGS); // javax.transaction.xa (java.transaction.xa)
System.out.println(DocumentBuilderFactory.class.getModule().getName()); // javax.xml.parsers (java.xml)
List<String> l = List.of("java.base needed its own import");
System.out.println(l);
}
}
+9
View File
@@ -0,0 +1,9 @@
import module java.base;
import module java.sql;
public class UnusedAmbiguity {
public static void main(String[] args) {
// Date is ambiguous between the two modules, but it is never used here, so this compiles.
System.out.println("no Date mentioned, no error");
}
}
+3
View File
@@ -0,0 +1,3 @@
/imports
System.out.println(List.of(1, 2).stream().map(x -> x * 2).collect(Collectors.toList()))
/exit