reflection: Method/Field/MethodHandle/VarHandle demos, module and final-field rules (JEP 500 on JDK 26), JMH call-cost numbers, contract tests

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b6NtPJHrkan4BXhCAM
This commit is contained in:
2026-11-08 18:14:04 +00:00
co-authored by Claude Sonnet 5.5
parent d7d5689f05
commit f6237d4117
19 changed files with 910 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
$ java -cp target/classes com.ankurm.reflection.ModuleRulesDemo
== setAccessible on your own class ==
Account.owner = carol
== setAccessible on a JDK private field ==
String lives in module : java.base
we live in module : unnamed module @6b95977 (unnamed=true)
java.lang open to us : false
trySetAccessible : false
setAccessible threw : InaccessibleObjectException
Unable to make field private final byte[] java.lang.String.value accessible: module java.base does not "opens java.lang" to unnamed module @6b95977
$ java --add-opens java.base/java.lang=ALL-UNNAMED -cp target/classes com.ankurm.reflection.ModuleRulesDemo
== setAccessible on your own class ==
Account.owner = carol
== setAccessible on a JDK private field ==
String lives in module : java.base
we live in module : unnamed module @3764951d (unnamed=true)
java.lang open to us : true
trySetAccessible : true
setAccessible worked, String.value is a byte[]