(或者是新增了一个参数和返回都是 object 的方法?
接口:
public interface itest {
T test(T s);
}
实现类:
public class test implements itest{
@Override
public String test(String s) {
return "test";
}
public static void main(String[] args) throws NoSuchMethodException {
Method[] testMethods = test.class.getMethods();
System.out.println("----------test-----------");
for (Method testMethod : testMethods) {
if (testMethod.getName().equals("test")) {
System.out.println("returnType : " + testMethod.getParameterTypes()[0]);
System.out.println("parameterTypes :" + testMethod.getReturnType());
}
}
System.out.println("----------itest----------");
Class>[] interfaces = test.class.getInterfaces();
Class> itest = interfaces[0];
Method[] itestMethods = itest.getMethods();
for (Method itestMethod : itestMethods) {
if (itestMethod.getName().equals("test")) {
System.out.println("returnType : " + itestMethod.getParameterTypes()[0]);
System.out.println("parameterTypes :" + itestMethod.getReturnType());
}
}
}
}
结果:
----------test-----------
returnType : class java.lang.String
parameterTypes :class java.lang.String
returnType : class java.lang.Object
parameterTypes :class java.lang.Object
----------itest----------
returnType : class java.lang.Object
parameterTypes :class java.lang.Object
求高人解答下 谢谢