Java如何获取方法的参数名称
1个回答
展开全部
package test;
import java.lang.reflect.Method;
public class TTT {
public static void main(String[] args) {
Class c = Test.class;
Method[] methods =c.getDeclaredMethods();
for (Method method : methods) {
System.out.print("方法的返回值"+method.getReturnType().getName());
System.out.print(" 方法名:"+method.getName()+"(");
Class[] paraTypes = method.getParameterTypes();
for (Class class1 : paraTypes) {
System.out.print("参数类型:"+class1.getSimpleName()+",");
}
System.out.println(")");
}
}
}
class Test
{
public void say(String word)
{
System.out.println(word);
}
public void say(String word,int n)
{
for(int i=0;i<n;i++){
System.out.println(word);
}
}
}
===============
方法的返回值void 方法名:say(参数类型:String,)
方法的返回值void 方法名:say(参数类型:String,参数类型:int,)
import java.lang.reflect.Method;
public class TTT {
public static void main(String[] args) {
Class c = Test.class;
Method[] methods =c.getDeclaredMethods();
for (Method method : methods) {
System.out.print("方法的返回值"+method.getReturnType().getName());
System.out.print(" 方法名:"+method.getName()+"(");
Class[] paraTypes = method.getParameterTypes();
for (Class class1 : paraTypes) {
System.out.print("参数类型:"+class1.getSimpleName()+",");
}
System.out.println(")");
}
}
}
class Test
{
public void say(String word)
{
System.out.println(word);
}
public void say(String word,int n)
{
for(int i=0;i<n;i++){
System.out.println(word);
}
}
}
===============
方法的返回值void 方法名:say(参数类型:String,)
方法的返回值void 方法名:say(参数类型:String,参数类型:int,)
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询