Caused by: java.lang.UnsupportedOperationException
来源:互联网 发布:nfc读卡软件 编辑:程序博客网 时间:2024/06/05 09:13
对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类的静态内部类!这样能会报错也就正常咯。
0 0
- Caused by: java.lang.UnsupportedOperationException
- Caused by: java.lang.UnsupportedOperationException
- bug宝典JAVA篇 Proguard混淆 [proguard] Caused by: java.lang.UnsupportedOperationException: Unsupported cla
- Caused by: java.lang.UnsupportedOperationException: Exceeded maximum number of wifi locks
- Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12
- Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1
- Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1
- Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1
- Android问题解决:Caused by: java.lang.UnsupportedOperationException: Can't convert to fraction: type=0x3
- Caused by: java.lang.UnsupportedOperationException: Can't convert value at index 75 to dimension
- Caused by: java.lang.UnsupportedOperationException: Can't convert to color: type=0x1
- Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1
- java.lang.UnsupportedOperationException: Not supported by BasicDataSource
- java.lang.UnsupportedOperationException: Not supported by BasicDataSource
- java.lang.UnsupportedOperationException: Not supported by BasicDataSource
- Caused by: java.lang.NoSuchMethodError
- Caused by: java.lang.InstantiationException
- Caused by: java.lang.NullPointerException
- pods的更新
- JavaWeb:报错信息The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
- OC04 NSString、NSArray、NSNumber-2
- 2023: [Usaco2005 Nov]Ant Counting 数蚂蚁
- 黑马程序员--继承和抽象类
- Caused by: java.lang.UnsupportedOperationException
- OC05 字典/数组
- Android APP开发流程
- OC05 集合
- Android Volley 网络请求框架图
- OC05 for_in快速遍历技术
- SVN用命令注册Window服务
- 桥接模式与适配器模式辨析
- KMP模板