Why does Java's TreeSet remove(Object) not take an E

前端 未结 4 739
刺人心
刺人心 2020-12-16 23:27

From the Java 6 TreeSet Documentation:

boolean remove(Object o):
    Removes the specified element from this set if it is present.

4条回答
  •  感情败类
    2020-12-17 00:05

    Well, each E is also an Object, and perhaps you have the E not as E at the moment (e.g from an Event source), which makes it convenient for you. Otherwise you just have to cast it to E only to remove it.

    From an equality point of view this doesn't matter: The given object's reference address is tested if it equals a set's content, so it doesn't matter of which class it is.

提交回复
热议问题