java reflection Flashcards

1
Q

What is the single meta-class called in java?

A

Class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the difference between getMethods and getDeclaredMethods?

A

getMethods - only public methods but includes inherited methods (public).

getDeclaredMethods - all methods in the class but no inherited.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to invoke private methods with reflection?

A
  1. use getDeclaredMethods
  2. use m.setAccessible(true);
  3. m.invoke()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What’s the difference between reflection in java and reflection in C# or squeak?

A

in java Can’t add / modify fields (structure), methods (behavior)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What’s missing in javas reflection?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly