The Java 7 Language Specifications say pretty early on:
"this specification does not describe reflection in any detail."
I'm wondering just that: how is Reflection implemented in Java?
I'm not asking how it's used, and I understand there might not be as specific an answer I'm looking for, but any information would be much appreciated.
I've found this on Stackoverflow, the analogous question about C#: How is reflection implemented in C#?
The main entry point of any Reflection activity is the
Class
class. From it you can getMethod
,Field
,Class
,Constructor
, andAnnotation
instances.If you look at the source code, you will notice that to retrieve any of the above, Java has to make a
native
call. For example,The implementation is done in native C code (and/or C++). Each JDK might differ, but you can look up the source code if it's available and you have patience. Details on the OpenJDK source code can be found in this question.