Java Generics – No Overload

Java Generics - No Overload

This topic is about Java Generics – No Overload.

A class is not allowed to have two overloaded methods that can have the same signature after type erasure.

class Box  {
   //Compiler error
   //Erasure of method print(List<String>) 
   //is the same as another method in type Box
   public void print(List<String> stringList) { }
   public void print(List<Integer> integerList) { }

In this topic we learned about Java Generics – No Overload. To know more, Click Here.

Leave a Reply