So upon getting the parameter(s) for a method via Reflection:
Class<?>[] params = m.getParameterTypes();
And assuming I'm looping through methods and looking for a method with only one parameter:
if(params.length > 1) {
continue;
}
Then getting that parameter if the length of the params array is 1:
Class<?> par = params[0];
When I try printing out the parameter's class with the getClass() method, it returns java.lang.Class.
However, when I get the superclass with the getSuperclass() method, it returns the superclass.
So for example:
System.out.println(par.getClass());
System.out.println(par.getSuperclass());
Assume the parameter of the method we have is a class called "PlayerDeathEvent", which extends the abstract "Event" class.
That being said, the output would be:
java.lang.Class
org.mypackage.Event
Is there a reason why this is occurring? I found a way around this with getCanonicalName, but I'm very curious as to why this occurs.
getClass()andgetSuperclass().paris already a java.lang.Class object. Just doSystem.out.println(par);.