3

Possible Duplicate:
Why aren't Java Collections remove methods generic?

I have a question about signature of java functions declared in Collection. The question is: why signature of add involves E (our type) but remove has parameter Object?

I have seen one response in WWW of this question, but I'm not sure that reason

"in remove we only need 1 operation: equals and Object provides it"

is plausible.

Community
  • 1
  • 1
user197284
  • 281
  • 1
  • 3
  • 7
  • There's a bunch of other places where there's a similar situation. For instance, `Map.push` takes generic parameters, but `Map.get` does not. – Etienne de Martel Dec 04 '11 at 06:59

1 Answers1

1

I think it's left over from pre-generic days. Both the add and remove methods used to take an Object argument. When generics were introduced, there was good reason to change the add method, but there really wasn't any good reason to change the remove method (because the reason you cited allowed it to remain as is).

My guess is that if it were designed from scratch today, Collection.remove would take a generic argument, not an anonymous Object.

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521