Java: Casting from List to List when B implements A?

You cannot cast it like that. Create a new one:

List<A> listA = new ArrayList<A>(listB);

The constructor takes Collection<? extends A>. It will point to the same references anyway.

Leave a Comment