Caused by: java.lang.UnsupportedOperationException
对Arrays.asList()返回的List进行操作之后报错Caused by: java.lang.UnsupportedOperationException
让我们来看一下Arrays.asList的源码:
/**
* Returns a {@code List} of the objects in the specified array. The size of the
* {@code List} cannot be modified, i.e. adding and removing are unsupported, but
* the elements can be set. Setting an element modifies the underlying
* array.
*
* @param array
* the array.
* @return a {@code List} of the elements of the specified array.
*/
@SafeVarargs
public static <T> List<T> asList(T... array) {
return new ArrayList<T>(array);
}
private static class ArrayList<E> extends AbstractList<E> implements
List<E>, Serializable, RandomAccess {
private static final long serialVersionUID = -2764017481108945198L;
private final E[] a;
ArrayList(E[] storage) {
if (storage == null) {
throw new NullPointerException("storage == null");
}
a = storage;
}
@Override
public boolean contains(Object object) {
if (object != null) {
for (E element : a) {
if (object.equals(element)) {
return true;
}
}
} else {
for (E element : a) {
if (element == null) {
return true;
}
}
}
return false;
}
@Override
public E get(int location) {
try {
return a[location];
} catch (ArrayIndexOutOfBoundsException e) {
throw java.util.ArrayList.throwIndexOutOfBoundsException(location, a.length);
}
}
@Override
public int indexOf(Object object) {
if (object != null) {
for (int i = 0; i < a.length; i++) {
if (object.equals(a[i])) {
return i;
}
}
} else {
for (int i = 0; i < a.length; i++) {
if (a[i] == null) {
return i;
}
}
}
return -1;
}
@Override
public int lastIndexOf(Object object) {
if (object != null) {
for (int i = a.length - 1; i >= 0; i--) {
if (object.equals(a[i])) {
return i;
}
}
} else {
for (int i = a.length - 1; i >= 0; i--) {
if (a[i] == null) {
return i;
}
}
}
return -1;
}
@Override
public E set(int location, E object) {
E result = a[location];
a[location] = object;
return result;
}
@Override
public int size() {
return a.length;
}
@Override
public Object[] toArray() {
return a.clone();
}
@Override
@SuppressWarnings({"unchecked", "SuspiciousSystemArraycopy"})
public <T> T[] toArray(T[] contents) {
int size = size();
if (size > contents.length) {
Class<?> ct = contents.getClass().getComponentType();
contents = (T[]) Array.newInstance(ct, size);
}
System.arraycopy(a, 0, contents, 0, size);
if (size < contents.length) {
contents[size] = null;
}
return contents;
}
}
索噶,原来返回的是Arrays类的静态内部类!这样能会报错也就正常咯。
Caused by: java.lang.UnsupportedOperationException的更多相关文章
- javax.net.ssl.SSLException: java.lang.UnsupportedOperationException
Loading KeyStore C:\Tool\jdk1.7.0_71\jre\lib\security\jssecacerts... Opening connection to www.googl ...
- Cause: java.lang.UnsupportedOperationException
运行web项目的时候出现以下错误: ### Cause: java.lang.UnsupportedOperationException at org.mybatis.spring.MyBati ...
- Arrays.asList()后调用add,remove这些method时出现java.lang.UnsupportedOperationException异常
String[] queryNames = request.getParameterValues("queryName"); List<String> queryNam ...
- java.lang.UnsupportedOperationException: Unable to create instance of org.fisco.bcos.web3j.abi.datatypes.generated.Int256
Contract Address : 0x967f92adc229b77dda64b42af21ea1ff1b0702eb Unable to create instance of org.fisco ...
- 【异常】Caused by: java.lang.ClassNotFoundException: org.springframework.dao.DataIntegrityViolationException
Caused by: java.lang.ClassNotFoundException: org.springframework.dao.DataIntegrityViolationException ...
- 编译异常 Caused by: java.lang.UnsupportedClassVersionError:
Caused by: java.lang.UnsupportedClassVersionError: com/sumingk/platform/service/impl/ServiceSysPerso ...
- java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12
最近使用Android Studio开发一个新项目,刚做完几个界面,跑在android 5.0上面很正常,因为都是挺简单的布局,本以为应该不存在兼容性问题(Flag啊). 偶然用了一个4.x的实机测试 ...
- Caused by: java.lang.NoClassDefFoundError:
tomcat启动不了 报错信息头如下: Caused by: java.lang.NoClassDefFoundError: at java.lang.Class.getDeclaredMethods ...
- android 自定义View Caused by: java.lang.ClassNotFoundException: Didn't find class
在android studio中, 自定义View 时,出现 Caused by: java.lang.ClassNotFoundException: Didn't find class 在查看包名和 ...
随机推荐
- PyAMF and django ForeignKey
In order to support this, PyAMF needs to provide a synonym mapping between fields. Until then, you c ...
- 获得 MongoDB for Node.js Developers 证书
前段时间由于项目需要,开始学习MongoDB,发现MongoDB官网的学习课程非常有帮助. 整个教学很有体系,包括: Video.quiz.Homework.Final Exam. 历时7周,拿到认证 ...
- HMM 自学教程(三)隐藏模式
本系列文章摘自 52nlp(我爱自然语言处理: http://www.52nlp.cn/),原文链接在 HMM 学习最佳范例,这是针对 国外网站上一个 HMM 教程 的翻译,作者功底很深,翻译得很精彩 ...
- Koa – 更加强大的下一代 Node.js Web 框架
Koa 是 Express 的开发团队设计的下一代 Web 框架,其目的是为 Web 应用程序提供更小,更具表现力,更坚实的基础.Koa 没有核捆绑任何中间件,并提供了一套优雅的方法,使服务器端开 ...
- [Python]爬虫v0.1
#coding:utf-8 import urllib ###### #爬虫v0.1 利用urlib2 和 字符串内建函数 ###### # 获取网页内容 def getHtml(url): page ...
- java高级---->Java动态代理的原理
Java动态代理机制的出现,使得 Java 开发人员不用手工编写代理类,只要简单地指定一组接口及委托类对象,便能动态地获得代理类.代理类会负责将所有的方法调用分派到委托对象上反射执行,在分派执行的过程 ...
- NVelocity的基本用法
NVelocity常用语法指令 默认情况下,NVelocity解析是不分大小写的,当然可以通过设置runtime.strict.math=true,采用严格解析模式. 严格区分大小写有时候还是挺有用途 ...
- 【rational rose】用例图
- java switch语句注意的事项
1.switch语句使用的变量只能是byte.char.short.string数据类型. 2.case后面gender数据必须是一个常量. 3.switch的停止条件: switch语句一旦比配上了 ...
- 在做excel导出时如何将excel直接写在输出流中
之前做excel导出时,我都是先将文件写在服务器上,然后再下载下来,后来发现原来可以直接将文件写在输出流里边. 下面是一个小demo: package com.huaqin.fcstrp.util; ...