Java generics uses type erasure. The bit in the angle brackets (<Integer>
and <String>
) gets removed, so you'd end up with two methods that have an identical signature (the add(Set)
you see in the error). That's not allowed because the runtime wouldn't know which to use for each case.
If Java ever gets reified generics, then you could do this, but that's probably unlikely now.