Polymorphisim in Java stands for many forms what can be achieved by overriding sub-class method. Regarding generics which allows to pass in generic values, such as ArrayList<Object>. Is that part of polymorphism concept?
Cheers
Polymorphisim in Java stands for many forms what can be achieved by overriding sub-class
Share
Generics and Polymorphism are two different things.
Generics are used primarily to specify which type is expected. You can use wildcards to define a range of types. E.g.
<? extends List>could apply to any type of List (LinkedList,ArrayList)Polymorphism is the concept that an object can have many types. So an object can be an instance of List and an instance of
ArrayListas an example.For example, imagine three classes
If you have an instance of
Dog, that object is both aDogAND anAnimal.Obviously the two fit together quite nicely as if you define an
ArrayList<Object>then you can add anyObjectto that list (Which is any class in Java)