2

I have two methods in same class:

public static Set<Type A> valueOf (Set<Type B>)
{}

public static Set<Type A> valueOf (Set<Type B>)
{}

I am getting same erasure compile time error. How do I resolve this?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
user620339
  • 851
  • 3
  • 20
  • 42
  • specify what the exact error is please – gideon Mar 18 '11 at 19:31
  • 3
    Your two methods above are identical -- this is clearly a mistake. Can you edit your message to fix it, please? – Ernest Friedman-Hill Mar 18 '11 at 19:55
  • The question is - why you would want to define the same method twice? Which one should the compiler pick when executing? The solution is obviously to separate the two methods by semantics. See also: http://stackoverflow.com/questions/1998544/method-has-the-same-erasure-as-another-method-in-type – Sorin Mocanu Mar 18 '11 at 19:57

2 Answers2

4

Your methods are exactly the same. The compiler won't know which one to use.

Also, in case you somehow meant

public static Set<Type A> valueOf (Set<Type A>)
{}

public static Set<Type B> valueOf (Set<Type B>)
{}

Those two methods are also the same, the type identifiers (A and B) get erased by the compiler, so they again end up having the same signature.

Brad Mace
  • 27,194
  • 17
  • 102
  • 148
Andrew T Finnell
  • 13,417
  • 3
  • 33
  • 49
1

To undestand what's going on, substitute each <GenericSomething> with Object since that is what the compiler sees - this is what's known as type erasure. Simply put, your both methods have the same signature, namely

public static Set<Object> valueOf (Set<Object>)
{}
Esko
  • 29,022
  • 11
  • 55
  • 82