How can I make reflection work on JDK 16 and later?
Reflection is another form of meta-programming, and just as valid, as the type-based parameters that you see in most languages these days. Reflection is powerful and generic, and reflective programs are a high order of maintainability (when used correctly, of course) and more so than purely object-orientated or procedural programs.
Reflection is fantastic for building tools for developers.
With the advent of Java 9 the approach to encapsulate has changed and the scary-sounding message appeared:
WARNING: An illegal reflective access operation has occurredHow to avoid this message? The simplest way is to avoid deep reflection is never call setAccessible(true).
That should solve the illegal reflective access. So what should we use instead of deep reflection? The best way is use property descriptor to get public methods to read and write the fields.
I created a project based on Java reflection for procedures without using setAccessible to access field values and modify them.
Comments
Post a Comment