8159527: Collections mutator methods should all be marked as optional operations

Reviewed-by: naoto, bpb
This commit is contained in:
Stuart Marks 2023-08-04 19:27:56 +00:00
parent 873d117932
commit b2add96c35
5 changed files with 62 additions and 53 deletions

View file

@ -537,7 +537,7 @@ public interface Collection<E> extends Iterable<E> {
* @param c collection containing elements to be removed from this collection
* @return {@code true} if this collection changed as a result of the
* call
* @throws UnsupportedOperationException if the {@code removeAll} method
* @throws UnsupportedOperationException if the {@code removeAll} operation
* is not supported by this collection
* @throws ClassCastException if the types of one or more elements
* in this collection are incompatible with the specified
@ -555,8 +555,8 @@ public interface Collection<E> extends Iterable<E> {
/**
* Removes all of the elements of this collection that satisfy the given
* predicate. Errors or runtime exceptions thrown during iteration or by
* the predicate are relayed to the caller.
* predicate (optional operation). Errors or runtime exceptions thrown during
* iteration or by the predicate are relayed to the caller.
*
* @implSpec
* The default implementation traverses all elements of the collection using
@ -569,10 +569,8 @@ public interface Collection<E> extends Iterable<E> {
* removed
* @return {@code true} if any elements were removed
* @throws NullPointerException if the specified filter is null
* @throws UnsupportedOperationException if elements cannot be removed
* from this collection. Implementations may throw this exception if a
* matching element cannot be removed or if, in general, removal is not
* supported.
* @throws UnsupportedOperationException if the {@code removeIf} operation
* is not supported by this collection
* @since 1.8
*/
default boolean removeIf(Predicate<? super E> filter) {