输出应如下:
foo(A,T1,T2) - >空隙
条(A,T1,T2,T3) - > INT
doo() - >双
public static class A {
void foo(int T1, double T2) { }
int bar(int T1, double T2, char T3) { return 1; }
static double doo() { return 1; }
}
static void displayMethodInfo(Object obj)
{
Class<?> a = obj.getClass();
Method[] methods = a.getDeclaredMethods();
for (Method y : methods) //print methods
{
System.out.print(y.getName() + "(" ); // + y.getDeclaringClass().getSimpleName());
Type[] types = y.getGenericParameterTypes(); //get parameter types
if (!(Modifier.isStatic((y.getModifiers()))))
{
//non-static method, output this class namr as the 1st argument
System.out.print(y.getName()); //display
if (types.length > 0)
{
//put a comma and space
System.out.print(", ");
}
}
for (Type z : types)
System.out.print(", " + z.toString());
System.out.println( ") " + " -> " + y.getGenericReturnType().toString()); //*/
/*
//print parameter of the method
int i = 0;
for (; i < types.length-1; i++)
{
System.out.print(removeClassFromName (types[i].toString()) + ", ");
}
if (types.length > 0) //print last parameter
{
System.out.print(removeClassFromName(types[i].toString()));
//print return type
System.out.println( " ) " + " -> " + removeClassFromName(y.getGenericReturnType().toString()));
} */
}
}
运行代码后,用我的代码输出代码,输出如下代码,它不能正确打印出类型。我该如何修复并正确输出?
bar(int,double,char) - &gt; INT
doo() - &gt;双
foo(int,double) - &gt;空隙
每当我重新编译并运行它时,输出都会有不同的顺序。