The main entry point of any Reflection activity is the Class
class. From it you can get Method
, Field
, Class
, Constructor
, and Annotation
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,
private native Field[] getDeclaredFields0(boolean publicOnly);
private native Method[] getDeclaredMethods0(boolean publicOnly);
private native Constructor<T>[] getDeclaredConstructors0(boolean publicOnly);
private native Class<?>[] getDeclaredClasses0();
private native byte[] getRawAnnotations(); // get converted to Annotation instances later
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.