2 回答

慕標5832272
TA貢獻1966條經驗 獲得超4個贊
用反射機制,簡單寫了一個例子,不懂的可以看一下相關api public class OwerMethodParam {
public static void main(String[] args) {
new OwerMethodParam().test("bb");
}
public void test(String aa) {
Method[] methods = OwerMethodParam.class.getDeclaredMethods(); //取得這個類的所有方法
if (methods != null) {
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if ("test".equals(method.getName())) { //取得本方法,這個方法是test,所以就用test比較
Class<?>[] paramsClass = method.getParameterTypes(); //取得參數列表的所有類
if (paramsClass != null) {
for (Class<?> class1 : paramsClass) {
System.out.println(class1.getName());
}
}
break;
}
}
- 2 回答
- 0 關注
- 554 瀏覽
添加回答
舉報
0/150
提交
取消