java - Rules for over-riding while using Collections -


this question has answer here:

why java wont allow over-riding? there missing?

class abc {     public void add (list<string> li)     {      }  } public class test extends abc {     public static void main(string args[])     {      }      @override     public void add (list<object> li)     {      } 

while allow method override if remove the

<object>  

and write list li in on riding method same

list<object> 

also add, allows over-riding if both list in over-ridden , over-riding method have same type.

list<string> - over-ridden method list<string> - over-riding method 

this limitation (design flaw? bug?) in how generics designed in java.

your expectation reasonable, way decided implement (and define) generics made infeasible.

however, if think it, design perhaps more reasonable expectation: in practical terms, list<string> cannot directly converted list<object> - has create whole new list, copy contents over.


Comments