0

Here is the code:

public class Test {    
    private static void print(List<Plant> plants) {
        
    }

    private static void print(List<Animal> animals) {

    }
}


class Animal {

}

class Plant {
   
}

When I want to overload print method in Test class for Animal and Plant lists, the compiler says that "both methods have same erasure". When I research "method erasure", I could not relate it to my situation.

Oğuzcan Budumlu
  • 511
  • 1
  • 4
  • 11

1 Answers1

1

Because both List<Plant> and List<Animal> are List (raw type) using type erasure, so compiler sees 2 print methods are identical.

lucas-nguyen-17
  • 5,516
  • 2
  • 9
  • 20