为什么父级的类型不允许使用 .class [已关闭]

why .class is not allowed on the parent's type [closed]

提问人:bsobaid 提问时间:11/17/2023 最后编辑:Stephen Cbsobaid 更新时间:11/17/2023 访问量:41

问:


编辑问题以包括所需的行为、特定问题或错误以及重现问题所需的最短代码。这将帮助其他人回答这个问题。

2天前关闭。

为什么不允许在泛型类型的父类上.class?

public class DataService<TYPE extends ClientData> extends BaseDataService<TYPE>{
    
    public DataService(){
         //So existing consumer dont have to pass clientData.class as argument
    
        super(ClientData.class) //compile error. 
                                // why cant I refer to the explicit type here?
    }
    
    public DataService(Class<TYPE> cls){
        //This is useful if I want to inherit from DataService
        super(cls);
    }
}
Java 泛型

评论


答: 暂无答案