Reputation: 86145
Have a base genric class like ClassBase<T>
I found I can use
ClassDerived extends ClassBase
or
ClassDerived<T> extends Classbase<T>
So basically it means I can remove generics in the derived class, is that right?
Upvotes: 2
Views: 1307
Reputation: 20651
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.
Upvotes: 1
Reputation: 234847
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"
Upvotes: 2