集合上的UnsupportedOperationException [英] UnsupportedOperationException on Collection

查看:51
本文介绍了集合上的UnsupportedOperationException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在研究 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆