Core Java: Type Erasure

Part of polymorphism, we have method overloading is one form where methods can have same name with different parameter types.

One such example would be below:-

following are my method signatures –

void mymethod(List<String> a, List<Integer> b);

void mymethod(List<Integer> c, List<String[]> d);

void mymethod(List<List<String>> e, List<Integer> f);

And surprisingly all these methods having same signature due to Type Earsure which removes generics from the Object type for considering parameter type. In the above case, all methods having List as Object type without considering generics inside.

To know more, read Type Erasure.

Leave a Reply

Your email address will not be published. Required fields are marked *