I stumbled upon an interesting error that I've never seen before, and can't explain why
Consider the following class
public class Sandbox<A,B> {
public void put(B b) {
}
public void put(A a) {
}
}
Looks okay to my eyes. So I compile it and then get this
name clash: put(B) and put(A) have the same erasure
Huh? How do two different generic types have the same signature? There completely separate!
I'm probably missing something completly basic, but I've just not run into this issue before. I've band-aid fixed the problem by calling the methods putA
and putB
, but I'm really curious to why this error happened in the first place.
Would someone mind explaining?