java 反射获取子类_java – 为什么当子类覆盖它们时,通过反射获得基类方法?

我有超级班:

class MyClass {

public void setValue(T value){

//insert code

}

public T getValue(){

return null;

}

}

那么我有一个具体的推导

class MyClassImp extends MyClass {

@Override

public void setValue(String value){

//insert code

}

@Override

public String getValue(){

return null;

}

}

在MyClassImpl上反映为:

Class clazz = MyClassImpl.class;

Method[] methods = clazz.getDeclaredMethods();

我得到两个超类实现java.lang.Object getValue(),void setValue(java.lang.Object)和java.lang.String getValue(),void setValue(java.lang.String).

根据Class.getDeclaredMethods()的Java文档

Returns an array of Method objects reflecting all the methods declared by the class or interface represented by this Class object. This includes public,protected,default (package) access,and private methods,but excludes inherited methods. The elements in the array returned are not sorted and are not in any particular order. This method returns an array of length 0 if the class or interface declares no methods,or if this Class object represents a primitive type,an array class,or void. The class initialization method is not included in the returned array. If the class declares multiple public member methods with the same parameter types,they are all included in the returned array.

为什么我得到超级类型的实现?

有没有我失踪的东西?

我需要这个的原因是我反思地在基类实现中调用setValue,我已经添加了一些特殊的注释注释,当然还有其他的约束.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值