Why aren't Java Collections remove methods generic?

前端 未结 10 2314
旧巷少年郎
旧巷少年郎 2020-11-22 04:49

Why isn\'t Collection.remove(Object o) generic?

Seems like Collection could have boolean remove(E o);

Then, when you ac

10条回答
  •  迷失自我
    2020-11-22 05:46

    Remove is not a generic method so that existing code using a non-generic collection will still compile and still have the same behavior.

    See http://www.ibm.com/developerworks/java/library/j-jtp01255.html for details.

    Edit: A commenter asks why the add method is generic. [...removed my explanation...] Second commenter answered the question from firebird84 much better than me.

提交回复
热议问题