开发者

How to inherit from a base generic class

Have a base genric class like ClassBase<T>

I found I can u开发者_运维问答se

ClassDerived extends ClassBase

or

ClassDerived<T> extends Classbase<T>

So basically it means I can remove generics in the derived class, is that right?


Since all generic type information is erased in the compilation process, of course you can do that. However, most compilers will generate a warning unless the warning is turned off or suppressed. For instance, if I write class Foo extends HashMap {}, Eclipse reports: "HashMap is a raw type. References to generic type HashMap should be parameterized"


You can extend the raw version of a generic class, that's correct. Of course your second example:

ClassDerived<T> extends Classbase

... actually re-introduces a type parameter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜