Java Reflection And Method Handles

Runtime access to code the compiler cannot check: what reflection costs beyond speed — no compile-time checking, invisible to refactoring and dead-code analysis, blocked by module encapsulation, and constrained by closed-world native-image analysis — the alternatives that keep the checking (interfaces, ServiceLoader, annotation processing, code generation), MethodHandles and VarHandles for genuinely dynamic access, and the security boundary around resolving a name that came from outside. Use when reflection appears in application code, when setAccessible needs --add-opens, when a framework works on the JVM and fails under native image, when a class name arrives from configuration or a payload, when Method.invoke or invokeWithArguments sits on a hot path, or when a runbook still sets sun.reflect.inflationThreshold or noInflation. FFM and JNI mechanics are jni-and-ffm, the annotations reflection reads are java-annotations, and deserialisation attack surface is java-serialization-hardening.

robsonkades 77e8478 5 files · 42.7 KB Updated

File contents

robsonkades/agent-skills/tree/main/skills/java-reflection-and-method-handles commit 77e8478b3b

Frequently asked questions

npx skillmds@latest add robsonkades/java-reflection-and-method-handles