How do you cast a List of supertypes to a List of subtypes?

For example, lets say you have two classes:

public class TestA {}
public class TestB extends TestA{}

I have a method that returns a List<TestA> and I would like to cast all the objects in that list to TestB so that I end up with a List<TestB>.

18 Answers
18

Leave a Comment