Add jdk28-preview module: JDK 28 early-access build, value classes, strict init flag, PEM, JSON incubator

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Gth99spB1CzQmBFofXmU4Z
This commit is contained in:
Claude
2026-09-28 08:48:04 +00:00
parent 57a04dc393
commit c8ff3acf09
15 changed files with 221 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
/** Compiles on every JDK. Does == on two boxed 1000s say true? */
public class IntegerIdentity {
public static void main(String[] args) {
Integer a = 1000, b = 1000;
System.out.println("Integer 1000 == Integer 1000: " + (a == b));
}
}
+13
View File
@@ -0,0 +1,13 @@
import jdk.incubator.json.*;
/** JEP 540: the incubating JSON API in module jdk.incubator.json. Needs --add-modules jdk.incubator.json. */
public class JsonDemo {
public static void main(String[] args) {
JsonValue doc = Json.parse("{\"name\":\"Ada\",\"langs\":[\"en\",\"fr\"],\"age\":36}");
System.out.println("name = " + doc.get("name").asString());
System.out.println("second language = " + doc.get("langs").get(1).asString());
System.out.println("age + 1 = " + (doc.get("age").asInt() + 1));
System.out.println("missing key -> " + doc.tryGet("email"));
System.out.println(Json.toDisplayString(doc, " "));
}
}
+15
View File
@@ -0,0 +1,15 @@
import java.security.*;
import java.security.spec.ECGenParameterSpec;
/** JEP 542: PEMEncoder / PEMDecoder. Preview in 25; does it still need --enable-preview on 28? */
public class PemRoundTrip {
public static void main(String[] args) throws Exception {
KeyPairGenerator g = KeyPairGenerator.getInstance("EC");
g.initialize(new ECGenParameterSpec("secp256r1"));
KeyPair kp = g.generateKeyPair();
String pem = PEMEncoder.of().encodeToString(kp.getPublic());
System.out.println(pem.lines().findFirst().get());
PublicKey back = PEMDecoder.of().decode(pem, PublicKey.class);
System.out.println("round trip equal: " + back.equals(kp.getPublic()));
}
}
+6
View File
@@ -0,0 +1,6 @@
/** JEP 539 (preview in JDK 28): a JVM field flag. javac sets it on value-class fields; an identity class is the control. */
public class StrictFieldProbe {
static value class Money { final long cents; Money(long c) { cents = c; } }
static class Legacy { final long cents; Legacy(long c) { cents = c; } }
public static void main(String[] args) { new Money(1); new Legacy(1); }
}
+16
View File
@@ -0,0 +1,16 @@
/** JEP 401 (preview in JDK 28): value classes and value records give up identity, so == compares state. */
public class ValueClasses {
value record Point(int x, int y) {}
public static void main(String[] args) {
Point p = new Point(1, 2), q = new Point(1, 2);
System.out.println("p == q: " + (p == q) + ", equals: " + p.equals(q));
System.out.println("isValue: " + p.getClass().isValue());
Object o = p;
try {
synchronized (o) { System.out.println("locked"); }
} catch (Throwable t) {
System.out.println("synchronized on a value object: " + t);
}
}
}