I have created my own custom class loader for loading a class to JVM. i can access the non static members using following code
MyLoader c=new MyLoader();
Class cls=c.loadClass("Hello");
Object obj=cls.newInstance()
cls.getMethod("show").invoke(obj);
But i don't know the procedure for accessing a static memebrs of a loaded class. Kindly provide a solution for this problem.
// String.class here is the parameter type, that might not be the case with you
Method method = clazz.getMethod("methodName", String.class);
Object o = method.invoke(null, "whatever");
In case the method is private use getDeclaredMethod()
instead of getMethod()
. And call setAccessible(true)
on the method object.