展开全部
先获取Method对象
以下仅供参考32313133353236313431303231363533e78988e69d8331333363373734package com.kidd.test.zhidao;
import java.lang.reflect.Method;
/**
* Hello world!
*
*/
public class Main {
public static void main(String[] args) {
Method method1 = null;
Method method2 = null;
try {
method1 = Class.forName("com.kidd.test.zhidao.Cat").getMethod("getName", (Class>[]) null);
method2 = Class.forName("com.kidd.test.zhidao.Cat").getMethod("getChilds", (Class>[]) null);
} catch (NoSuchMethodException ex) {
ex.printStackTrace();
} catch (SecurityException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
if (null != method1) {
System.out.println(method1.getGenericReturnType().getTypeName());
}
if (null != method2) {
System.out.println(method2.getGenericReturnType().getTypeName());
}
}
}
class Cat {
private String name;
private Cat[] childs;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Cat[] getChilds() {
return childs;
}
public void setChilds(Cat[] childs) {
this.childs = childs;
}
}