Add java28-features module: the JDK 28 JEP list so far, one example per JEP on 28-ea+26, behaviour changes against JDK 27

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b7N4ZDbUtA3ofqAqRV
This commit is contained in:
asmhatre
2026-12-03 09:10:29 +05:30
co-authored by Claude Sonnet 5.5
parent c0062ea398
commit d4b8552957
37 changed files with 767 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
// Non-JEP changes from the JDK 28 release notes. Run the same file on JDK 27 and JDK 28.
import java.lang.foreign.Linker;
import java.lang.foreign.ValueLayout;
import java.security.Security;
import java.text.ListFormat;
import java.util.List;
import javax.crypto.Cipher;
import java.security.KeyPairGenerator;
public class Behaviour {
static class NotSerializable {}
public static void main(String[] args) throws Exception {
System.out.println("-- ListFormat with single quotes in a custom pattern");
try {
var f = ListFormat.getInstance(new String[] {"{0}, {1}", "{0}, {1}", "{0} and {1}", " '{0}', {1} ", ""});
System.out.println("[" + f.format(List.of("bar", "foo")) + "]");
} catch (Exception e) {
System.out.println(e.getClass().getSimpleName() + ": " + e.getMessage());
}
System.out.println("-- RSA/ECB/PKCS1Padding");
var kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(2048);
var cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.ENCRYPT_MODE, kpg.generateKeyPair().getPublic());
System.out.println("cipher initialised");
System.out.println("-- canonical size_t layout");
var sizeT = Linker.nativeLinker().canonicalLayouts().get("size_t");
System.out.println(sizeT + " equals JAVA_LONG: " + sizeT.equals(ValueLayout.JAVA_LONG));
System.out.println("-- ReflectionFactory on a non-serializable class");
var factoryClass = Class.forName("sun.reflect.ReflectionFactory");
Object factory = factoryClass.getMethod("getReflectionFactory").invoke(null);
var one = factoryClass.getMethod("newConstructorForSerialization", Class.class);
System.out.println("one-arg : " + one.invoke(factory, NotSerializable.class));
var two = factoryClass.getMethod("newConstructorForSerialization", Class.class, java.lang.reflect.Constructor.class);
try {
Object c = two.invoke(factory, NotSerializable.class, Object.class.getDeclaredConstructor());
System.out.println("two-arg : returned a constructor");
} catch (java.lang.reflect.InvocationTargetException e) {
System.out.println("two-arg : " + e.getCause().getClass().getSimpleName() + ": " + e.getCause().getMessage());
}
}
}
@@ -0,0 +1,7 @@
import java.util.List;
class RawConditional {
Integer first(boolean b, List raw, List<Integer> parameterized) {
return (b ? parameterized : raw).get(0);
}
}
@@ -0,0 +1,10 @@
class SwitchGuard {
static boolean check(String s) throws Exception { return s.isEmpty(); }
static String classify(Object o) {
return switch (o) {
case String s when check(s) -> "empty";
default -> "other";
};
}
}