I have the following code snippet, which I can't understand why doesn't work:
List<Object[]> listOfObjectArrays;
listOfObjectArrays = new ArrayList<>();
Object[] objectArray = new Object[] {1, "two", null};
listOfObjectArrays.add(objectArray);
// works just fine
listOfObjectArrays = Arrays.asList(objectArray, objectArray);
// works just fine
listOfObjectArrays = Arrays.asList(objectArray); // *
// compile error: Incompatible types. Required: List<java.lang.Object[]> Found: List<java.lang.Object>
listOfObjectArrays = Arrays.asList(new Object[] {1, "two", null});
// compile error: Incompatible types. Required: List<java.lang.Object[]> Found: List<java.lang.Object>
Could somebody please point me in the right direction?
I already saw Jon Skeet's answer on an other question, but the last example there does not work for me. Even if I add a cast to either Object
or Object[]
in the line marked with *
I get a compile error.
>.asList(objectArray)`
– Jorge Campos Sep 11 '15 at 11:24