java 泛型接口 实现类_为什么泛型接口的实现类在类型擦除后多出了一个保留了原来的参数的方法?...

(或者是新增了一个参数和返回都是 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

求高人解答下 谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值