集合上的UnsupportedOperationException [英] UnsupportedOperationException on Collection
问题描述
在研究 Collection
API时,我们发现某些方法( add
, remove
,...)可能会抛出如果Collection的当前实现不支持这些功能,则为java.lang.UnsupportedOperationException
.
实际上,在JDK中是否存在不支持这些方法的具体 Collection
?
非常感谢您的回答.
显而易见的示例是从 Collections.unmodifiableCollection()
和其他类似方法返回的实现.会更改 Collection
的方法将引发此异常.
While studying the Collection
API, we find that some methods (add
, remove
,...) may throw a java.lang.UnsupportedOperationException
if the current implementation of the Collection does not support those functionalities.
Is there,actually, in the JDK, a concrete Collection
that does not support those methods ?
Thanks a lot for your answers.
The obvious examples are the implementations returned from, say, Collections.unmodifiableCollection()
and other similar methods. Methods that would change the Collection
throw this exception.
这篇关于集合上的UnsupportedOperationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!