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 15:08:50 +00:00
committed by Claude
co-authored by Claude Sonnet 5
commit f59c1de96d
152 changed files with 5049 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
/**
* A primitive pattern placed after the reference pattern that already matches every Integer.
* The compiler rejects it on both 26 and 27. Driven by scripts/broken-on-27.sh.
*/
public class Dominated {
static String describe(Object o) {
return switch (o) {
case Integer boxed -> "an Integer";
case int primitive -> "an int"; // dominated: every Integer is already caught above
default -> "something else";
};
}
}
+17
View File
@@ -0,0 +1,17 @@
import java.lang.LazyConstant;
/**
* JDK 26 code for the lazy constants preview. It compiles on 26 and fails on 27:
* LazyConstant.orElse(...) and LazyConstant.isInitialized() were removed in the third preview.
* Driven by scripts/broken-on-27.sh.
*/
public class Lazy26 {
static final LazyConstant<String> GREETING = LazyConstant.of(() -> "hello");
public static void main(String[] args) {
if (!GREETING.isInitialized()) {
System.out.println("not yet: " + GREETING.orElse("<unset>"));
}
System.out.println(GREETING.get());
}
}
+26
View File
@@ -0,0 +1,26 @@
import java.security.DEREncodable;
import java.security.PEM;
import java.security.PEMDecoder;
import java.security.Provider;
import java.security.Security;
/**
* JDK 26 code for the PEM preview API. It compiles on 26 and fails on 27.
* Three things moved between the second and third preview (JEP 524 -> JEP 538):
* 1. DEREncodable was renamed BinaryEncodable
* 2. PEMDecoder.withFactory(Provider) became withFactoriesOf(Provider)
* 3. PEM was a record whose content() returned a String; it is now a class whose content() returns byte[]
* Driven by scripts/broken-on-27.sh, which commits the compiler's own messages.
*/
public class Pem26Style {
public static void main(String[] args) {
String text = "-----BEGIN ANKURM DEMO-----\naGVsbG8=\n-----END ANKURM DEMO-----\n";
DEREncodable decoded = PEMDecoder.of().decode(text); // 1
Provider provider = Security.getProviders()[0];
PEMDecoder viaProvider = PEMDecoder.of().withFactory(provider); // 2
if (decoded instanceof PEM pem) {
String base64Text = pem.content(); // 3
System.out.println(pem.type() + " / " + base64Text);
}
}
}
@@ -0,0 +1,23 @@
import java.util.List;
import java.util.concurrent.StructuredTaskScope;
import java.util.concurrent.StructuredTaskScope.Joiner;
/**
* JDK 26 code for the structured concurrency preview. It compiles on 26 and fails on 27:
* StructuredTaskScope gained a third type parameter (the exception join() throws), and
* FailedException / TimeoutException no longer exist. Driven by scripts/broken-on-27.sh.
*/
public class StructuredScope26 {
public static void main(String[] args) throws Exception {
try (StructuredTaskScope<String, List<String>> scope =
StructuredTaskScope.open(Joiner.<String>allSuccessfulOrThrow())) {
scope.fork(() -> "price=42");
List<String> results = scope.join();
System.out.println(results);
} catch (StructuredTaskScope.FailedException e) {
System.out.println("a subtask failed: " + e.getCause());
} catch (StructuredTaskScope.TimeoutException e) {
System.out.println("timed out");
}
}
}