package cnblogs; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Type; /** * Created by Kischn on 2015/11/25. */ public class ReflectTest { public static void main(String[] args) { Class<ReflectTest> t = ReflectTest.class; Method[] declaredMethods = t.getMethods(); for(Method method : declaredMethods) { System.out.print(method.getReturnType()); System.out.print(' '); System.out.println(method.getName()); System.out.println("params:"); Type[] genericParameterTypes = method.getGenericParameterTypes(); for (Type type : genericParameterTypes) { System.out.println(type.getTypeName()); } System.out.println("---------------"); } } public void sayHello(String name){ System.out.print("hello" + name); } }
void main
params:
java.lang.String[]
---------------
void sayHello
params:
java.lang.String
---------------
void wait
params:
---------------
void wait
params:
long
int
---------------
void wait
params:
long
---------------
boolean equals
params:
java.lang.Object
---------------
class java.lang.String toString
params:
---------------
int hashCode
params:
---------------
class java.lang.Class getClass
params:
---------------
void notify
params:
---------------
void notifyAll
params:
---------------
题主是要这样的吗?
谢谢,要的就是这个样子,已经get了
然后呢?
就是想确定类中方法的入参类型
@zz,: .NET中的反射是可以获取ParameterInfo的,然后就得知参数类型了。我想JAVA中也应该有类似的东西吧。
@Firen: 谢谢您,问题解决了