Can you explain me why does this happen and how can I fix it please?
So I'm using Oracle-ADF and I'm using shuttle components. I get the selected values using the sos1.getValue();
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
However, this line of code is going bananas:
sos1Value = (ArrayList) Arrays.asList(sos1.getValue());
And I keep getting java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList
I've tried other ways like: sos1Value = (ArrayList) sos1.getValue();
But I keep having the same problem, what can I do?
Best Answer
Arrays.asList
returns aList
implementation, but it's not ajava.util.ArrayList
. It happens to have a classname ofArrayList
, but that's a nested class withinArrays
- a completely different type fromjava.util.ArrayList
.If you need a
java.util.ArrayList
, you can just create a copy:If you don't need an ArrayList just remove the cast:
(if you don't need any members exposed just by
ArrayList
).