Java 27 and 26: runnable demos and captured output for every JEP, plus version lanes

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01B38FGKKam5SCGgwgduVAh3
This commit is contained in:
2026-09-21 14:47:46 +00:00
committed by Claude
co-authored by Claude Sonnet 5
commit da55954922
150 changed files with 4968 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
/**
* "Unnamed patterns and unnamed classes are also final in 25" is only half true. Unnamed variables and patterns (the
* underscore) were finalised in Java 22 (JEP 456). What became final in 25 is compact source files and instance main
* methods (JEP 512), the successor to "unnamed classes". This file checks the underscore half.
* Chapter: docs/14-lanes-21-to-25.md
*/
public class UnnamedVariables {
record Point(int x, int y) {}
public static void main(String[] args) {
Object o = new Point(3, 4);
if (o instanceof Point(int x, _)) {
System.out.println("matched a Point, x = " + x + ", y ignored with _");
}
try {
Integer.parseInt("nope");
} catch (NumberFormatException _) {
System.out.println("caught NumberFormatException without naming it");
}
}
}