java基本类型的反射问题

来源:百度知道 编辑:UC知道 时间:2024/06/01 11:09:33
为了找到正确的反射,“?”号的地方填什么?谢谢!

public class TestClass {
public void fun(double d1,double d2){
System.out.println("调用fun(double, double)");
}
public void fun(double d){
System.out.println("调用fun(double)");
}
public void fun(Integer i){
System.out.println("调用fun(int)");
}
public void fun2(int i){
System.out.println("调用fun2(int)");
}

/**
* @param args
*/
public static void main(String[] args) {

TestClass test=new TestClass();

try {
Method method1=test.getClass().getMethod("fun2", ???);//这个问号的地方应该填什么?或者还有其他的方法可以找到正确的方法反射?
System.out.println(method1.toString());
method1.invoke(test, 1);
} catch (Exception e) {
e.printStackTrace();
}

}

}

/////////////////////////////////////////
import java.lang.reflect.*;

public class TestClass {
public void fun(double d1,double d2){
System.out.println("调用fun(double, double)");
}
public void fun(double d){
System.out.println("调用fun(double)");
}
public void fun(Integer i){
System.out.println("调用fun(int)");
}
public void fun2(int i){
System.out.println("调用fun2(int)");
}

/**
* @param args
*/
public static void main(String[] args) {

TestClass test=new TestClass();

try {
Method method1=test.getClass().getDeclaredMethod("fun2", int.class);//这个问号的地方应该填什么?或者还有其他的方法可以找到正确的方法反射?
System.out.println(method1.toString());
method1.invoke(test, 1);
} catch (Exception e) {
e.printStackTrace();
}

}

}

TestClass.class