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.
精彩评论