Method has the same erasure as another method in type

前端 未结 7 780
时光取名叫无心
时光取名叫无心 2020-11-22 05:50

Why is it not legal to have the following two methods in the same class?

class Test{
   void add(Set ii){}
   void add(Set ss){}         


        
相关标签:
7条回答
  • 2020-11-22 06:54

    The problem is that Set<Integer> and Set<String> are actually treated as a Set from the JVM. Selecting a type for the Set (String or Integer in your case) is only syntactic sugar used by the compiler. The JVM can't distinguish between Set<String> and Set<Integer>.

    0 讨论(0)
提交回复
热议问题