Generics and Polymorphism

In the previous two articles related to Generics we learned about generics usage and concepts. In this article, let us focus on the aspect of polymorphism and how generics support polymorphism. In general, polymorphism applies to the base type of the collection. For example, the following code creates an ArrayList which can hold Integers. Note that in the following code the base type is List and sub type is ArrayList(since ArrayList is a sub class of List). List<Integer> numberList = new ArrayList<Integer>(); In the above code snippet, List and ArrayList are ‘base’ types and Integer is the generic type. Because […]

Generics and Polymorphism Read More »