Add java25-features module: the 18 JEPs of JDK 25 with runnable demos, captured output and compile-error cases
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b5uFE41EgmSXEP4axJ
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
876ae1bb5c
commit
1fb1455734
@@ -0,0 +1,9 @@
|
||||
import module java.base;
|
||||
import module java.sql; // java.sql exports java.sql.Date, java.base exports java.util.Date
|
||||
|
||||
public class AmbiguousModuleImport {
|
||||
public static void main(String[] args) {
|
||||
Date d = null; // which Date?
|
||||
System.out.println(d);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// JEP 507 is a preview in 25: compiling without --enable-preview must fail.
|
||||
public class PreviewWithoutFlag {
|
||||
public static void main(String[] args) {
|
||||
long v = 42L;
|
||||
if (v instanceof int i) System.out.println(i);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// The Java 21 preview shape (ShutdownOnFailure) does not exist in 25: this must fail to compile.
|
||||
import java.util.concurrent.StructuredTaskScope;
|
||||
public class ShutdownOnFailure21Style { public static void main(String[] a) throws Exception {
|
||||
try (var s = new StructuredTaskScope.ShutdownOnFailure()) { var f = s.fork(() -> "x"); s.join(); System.out.println(f.get()); } } }
|
||||
@@ -0,0 +1,12 @@
|
||||
// JEP 513 allows statements before super(), but not anything that reads `this`.
|
||||
public class ThisBeforeSuper {
|
||||
static class Base { Base() {} }
|
||||
static class Child extends Base {
|
||||
int side = 4;
|
||||
String describe() { return "child"; }
|
||||
Child() {
|
||||
System.out.println(describe()); // instance method call before super(): rejected
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user