Hi,
> 8: Collection<Bar> stuff = (Collection<Bar>)getStuff();
>
[quoted text clipped - 4 lines]
> Can anyone explain exactly what this means and why the above code may
> be dangerous?
It means that the cast is only checked for "Collection", not for
"Collection<Bar>".
Ciao,
Ingo
hiwa - 24 Aug 2005 19:33 GMT
> Hi,
>
[quoted text clipped - 12 lines]
> Ciao,
> Ingo
No. It is because wildcard ? for Java generics means 'specific some
class extending Foo' and doesn't mean
'any class extending Foo' as the OP have had expected. In other
words, the return value from the method
could be other Collection<? extends Foo> than Collection<Bar>.