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:
asmhatre
2026-11-25 13:17:10 +05:30
co-authored by Claude Sonnet 5.5
parent 876ae1bb5c
commit e5877f4bcf
35 changed files with 445 additions and 1 deletions
@@ -0,0 +1,27 @@
/** JEP 513 (final in 25): statements may run before super(...) as long as they do not touch `this`. */
public class FlexibleConstructorDemo {
static class Shape {
final String describe;
Shape() { this.describe = describe(); } // calls an overridden method from the super constructor
String describe() { return "shape"; }
}
static class Square extends Shape {
final int side;
Square(int side) {
if (side <= 0) throw new IllegalArgumentException("side must be positive, got " + side); // before super()
this.side = side; // assigning a field before super() is allowed
super();
}
@Override String describe() { return "square side=" + side; } // sees side, not the default 0
}
static class Old extends Shape {
final int side;
Old(int side) { super(); this.side = side; }
@Override String describe() { return "old square side=" + side; }
}
public static void main(String[] args) {
System.out.println(new Square(4).describe);
System.out.println(new Old(4).describe);
try { new Square(-1); } catch (IllegalArgumentException e) { System.out.println("rejected: " + e.getMessage()); }
}
}