Re: Java Generics - "super" keyword usage
Olivier Lefevre <[email protected]>
| Newsgroups | gmane.comp.windows.devel.java.advanced |
|---|---|
| Message-ID | <[email protected]> |
> So do you mean something like this:
No, I was just explaining the problem. In general it does not make
sense to have in the return type a parameter T that is not used in
the method parameters, unless it be a factory, e.g.,
public static HashSet<T> newHashSet() { return new HashSet<T>(); }
In this case it makes sense because you tell the method you want a
something parametrized over T and it contrives to create and return
just that. In your case you say a want a Foo<T> but you return a
Foo<X>, where all X and T have in common are that they have a common
parent. So it is your design that is the problem.
> But this causes a compiler warning.
As it should. That X and T are identical cannot be ruled out since
they both implement the same interface but it is no sure thing,
hence the warning.
Regards,
-- O.L.
===================================
This list is hosted by DevelopMentor® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com