如果方法是public的,是可以调用的public class A { public void f(String str){ System.out.println(str); } } public static void main(String[] args) { try { Class c = Class.forName("A"); Method m = c.getMethod("f", String.class); m.invoke(c.newInstance(), "invoke the method");
TypeVariable<Method>[] getTypeParameters()
返回 TypeVariable 对象的数组,这些对象描述了由 GenericDeclaration 对象表示的一般声明按声明顺序来声明的类型变量。
如果方法是public的,是可以调用的public class A {
public void f(String str){
System.out.println(str);
}
} public static void main(String[] args) {
try {
Class c = Class.forName("A");
Method m = c.getMethod("f", String.class);
m.invoke(c.newInstance(), "invoke the method");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}
}
为什么private 就的不能访问
反射机制是可以调用一切方法的吗?