日期:2014-05-20 浏览次数:20956 次
package test;
public interface Parent<R> {
    public R parentMethod();
}
package test;
public interface Child extends Parent<ActualType>{
    
    public ActualType ChildMethod();
}
package test;
public class ActualType {
}
package test;
import java.lang.reflect.Method;
public class Test {
    /**
     * @param args
     */
    public static void main(String[] args) {
        Method [] methods = Child.class.getMethods();
        for(Method method : methods){
            Class<?> clazz = method.getReturnType();
            System.out.println("Method:"+method.getName()+",ReturnType:"+clazz.getName());
        }
    }
}
public interface Parent<R> { //这个R是泛型,编译时被擦除,
                                 //因为编译器不知道R将被用户赋予什么类型,但又不能不编译,
                                 //所以统一用Object来管理
    public R parentMethod(); //所以这里返回的R就是Object
}
public interface Child extends Parent<ActualType>{ //这个ActualType是具体存在的类型
                                                          //编译时编译器能确定这个具体的类型
    
    public ActualType ChildMethod(); //所以这里返回的就是确定的ActualType
}
------解决方案--------------------