RSF
2018-07-06 16:24
package com.imooc;
import java.lang.reflect.Method;
public class Example {
public static void main(String[] args) {
A a1 = new A();
Class c = a1.getClass();
try {
//Method m = c.getMethod("print",new Class[]{int.class,int.class});
Method m = c.getMethod("print",new Class[]{int.class,int.class});
Object object = m.invoke(a1,10,20);
} catch (Exception e) {
e.printStackTrace();
}
}
}
class A{
public void print(int a,int b){
System.out.println(a+b);
}
private void print(String a,String b){
System.out.println(a.toUpperCase()+","+b.toLowerCase());
}
}
没ctrl+s?
运行没毛病啊
反射——Java高级开发必须懂的
151466 学习 · 335 问题
相似问题