所以我正在查看 TreeSet 类中的 remove() 方法,该方法的返回类型为布尔值。java api 表示,如果我们要删除的项目在树中,并且被删除,则该方法返回 true。如果项目不在树中,或者已经被删除,这个方法会引发异常吗?我可以修改该方法,以便在未删除元素时返回 false 吗?
remove
public boolean remove(Object o)
Removes the specified element from this set if it is present.(...)
Returns true if this set contained the element (or equivalently, if this set changed as a result of the call). (This set will not contain the element once the call returns.)