In a library, there is a function takes a Class object as parameter:
public void libMethod(Class<?> cls){...}
I need to invoke this library function in Java Reflection way.
For example I have a class :
public MySchool extends School{...}
I want to pass MySchool class to the library function. I tried:
//I can successfully get library class & a instance of it
Class<?> libClass = GET_LIB_CLASS();
//How can I define the type for the parameter?
Method m = libClass.getDeclaredMethod("libMethod", new Class[]{MySchool.class});
return m.invoke(libClass.newInstance(), MySchool.class);
I tried in above way, but it doesn't work.
How can I define the type for the parameter in my above java reflection way ?