问题描述
你能解释我为什么会发生这种情况,我怎么能解决这个问题吗?
Can you explain me why does this happen and how can I fix it please?
所以我使用Oracle-ADF和我使用的航天飞机部件。我得到使用选定的值 sos1.getValue();
So I'm using Oracle-ADF and I'm using shuttle components. I get the selected values using the sos1.getValue();
本的getValue()方法返回一个对象,我想将它转化成一个ArrayList,所以我可以稍后再处理。因此,我创建了的ArrayList sos1Value
The getValue() method returns an object and I'm trying to convert it to an ArrayList so I can work with it later. Therefore I've created the ArrayList sos1Value
不过,此行code的打算香蕉:
However, this line of code is going bananas:
sos1Value = (ArrayList) Arrays.asList(sos1.getValue());
和我一直有一个 java.lang.ClassCastException:java.util.Arrays中的ArrayList $不能转换为java.util.ArrayList中的
我tryed其他方式,如: sos1Value =(ArrayList的)sos1.getValue();
I've tryed other ways like: sos1Value = (ArrayList) sos1.getValue();
但我一直有同样的问题,我该怎么办?
But I keep having the same problem, what can I do?
推荐答案
Arrays.asList
返回列表
实施,但它不是一个的java.util.ArrayList
。它发生在有的ArrayList
A类名,但是这是阵列内的嵌套类
- 一个完全不同的类型,从的java.util.ArrayList
。
Arrays.asList
returns a List
implementation, but it's not a java.util.ArrayList
. It happens to have a classname of ArrayList
, but that's a nested class within Arrays
- a completely different type from java.util.ArrayList
.
如果您的需求的一个的java.util.ArrayList
,你可以创建一个副本:
If you need a java.util.ArrayList
, you can just create a copy:
ArrayList<Foo> list = new ArrayList<>(Arrays.asList(sos1.getValue());
或
List<Foo> list = new ArrayList<>(Arrays.asList(sos1.getValue());
(如果你没有需要通过 ArrayList中刚露出任何成员
)。
这篇关于java.lang.ClassCastException:java.util.Arrays中的ArrayList $不能转换为java.util.ArrayList中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!