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:
co-authored by
Claude Sonnet 5.5
parent
c0062ea398
commit
d4b8552957
@@ -0,0 +1,23 @@
|
||||
// JEP 539: strict field initialization is a JVM feature; javac uses it for value classes.
|
||||
// Compile this file with --enable-preview, then let it read its own class files.
|
||||
import java.lang.classfile.ClassFile;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class StrictFields {
|
||||
static final int ACC_STRICT_INIT = 0x0800;
|
||||
|
||||
value record Point(int x, int y) {}
|
||||
record Plain(int x, int y) {}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
for (String name : new String[] {"StrictFields$Point", "StrictFields$Plain"}) {
|
||||
var model = ClassFile.of().parse(Files.readAllBytes(Path.of(args[0], name + ".class")));
|
||||
for (var field : model.fields()) {
|
||||
int mask = field.flags().flagsMask();
|
||||
System.out.printf("%-20s %s flags=0x%04x strictly-initialized=%b%n",
|
||||
name, field.fieldName().stringValue(), mask, (mask & ACC_STRICT_INIT) != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user