import java.lang.reflect.Method;
public class Test1 {
public static void main(String[] args) {
try {
Class<?> clazz = Class.forName("House");
//获取本类的所有方法,存放入数组
Method[] methods = clazz.getDeclaredMethods();
for (Method method : methods) {
System.out.println("方法名:"+method.getName());
//获取本方法所有参数类型,存入数组
Class<?>[] getTypeParameters = method.getParameterTypes();
if(getTypeParameters.length==0){
System.out.println("此方法无参数");
}
for (Class<?> class1 : getTypeParameters) {
String parameterName = class1.getName();
System.out.println("参数类型:"+parameterName);
}
System.out.println("****************************");
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
class test01 {
public test01(){
System.out.println("我是tset01");
}
public void t1(){}
public void t2(String sss){}
public void t3(Integer integer,Boolean boo,test02 t){}
}
class test02{}
获取某个类的方法名及参数类型java
最新推荐文章于 2024-07-13 02:36:06 发布