0

I've come across an example where I'm not sure about the behavior of Generics syntax.

public void m1(List<String> list) {
    System.out.println("List size" + list.size());
}

public void m1(List<Integer> list) {
}

Here, m1 method is overloaded but it gives compile time error in Eclipse as,

Erasure of method m1(List) is the same as another method in type Test

Is the generic syntax of the methods is removed at compile time? Any ideas why is this happening?

fastcodejava
  • 39,895
  • 28
  • 133
  • 186
VPK
  • 3,010
  • 1
  • 28
  • 35
  • Have a look at [this](http://stackoverflow.com/questions/1998544/method-has-the-same-erasure-as-another-method-in-type) – Devas Jan 17 '17 at 06:13

1 Answers1

0

The compiler doesn't remove anything from your .java file instead it creates a .class file and it doesn't copy comments, imports, or all the generic information (some is still there). Please refer below thread for more information: Are generics removed by the compiler at compile time

Community
  • 1
  • 1