How to cast a list of inheriting objects to a collection of objects in Java ?

Posted by Kartoch on Stack Overflow See other posts from Stack Overflow or by Kartoch
Published on 2010-05-02T20:00:16Z Indexed on 2010/05/02 20:08 UTC
Read the original article Hit count: 142

Filed under:
|
|

I've a collection type:

Collection<A> collecA

And I've a list in my object:

List<B> listB

Where B is extending A

class B extends A { ... }

But I can't do the following:

collecA = listB

I can't understand why since Collection is implemented by List.

© Stack Overflow or respective owner

Related posts about java

Related posts about generics