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 = 0i <methods.lengthi++) {
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
}
}
package testimport 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=0i<ni++){
System.out.println(word)
}
}
}
===============
方法的返回值void 方法名:say(参数类型:String,)
方法的返回值void 方法名:say(参数类型:String,参数类型:int,)