java reflection Flashcards
What is the single meta-class called in java?
Class
What is the difference between getMethods and getDeclaredMethods?
getMethods - only public methods but includes inherited methods (public).
getDeclaredMethods - all methods in the class but no inherited.
How to invoke private methods with reflection?
- use getDeclaredMethods
- use m.setAccessible(true);
- m.invoke()
What’s the difference between reflection in java and reflection in C# or squeak?
in java Can’t add / modify fields (structure), methods (behavior)
What’s missing in javas reflection?
Reflection is introspection only (unlike squeak
and C#)
– Can’t add / modify fields (structure), methods (behavior)
• Implementation is not available
– Program logic is not reflected (cannot change methods’
source code)
• Major performance impact
– Much slower then doing the same operations directly…
• Complex code