-1
List<Object> al = Arrays.asList("ABC", "XYZ");

This code works fine in Java11 but when I try this in Java12, it gives an error Cannot cast from List to ArrayList

Any hint what I am missing?

Thanks for the help.

Manish
  • 159
  • 2
  • 16
Saili
  • 7
  • 2
  • 1
    You might want to look at https://stackoverflow.com/questions/60240353/not-able-to-create-list-of-string-object-in-java12 – Progman Feb 15 '20 at 18:37
  • The above code works fine for me in [openjdk version "12" 2019-03-19](https://jdk.java.net/java-se-ri/12). But `List` should probably be `List`, in this specific case. – andrewJames Feb 15 '20 at 18:52

1 Answers1

0

First, we need to check whether the value of setValues is a list or nested list

ValueRange body=new ValueRange().setValues(Arrays.asList(Arrays.asList("ABC", "XYZ"))); the above will give the results [[ABC, XYZ]] -> Nested array

Instead, try like this

ValueRange body=new ValueRange().setValues(new ArrayList<>(Arrays.asList("ABC", "XYZ")));

This gives results - > [ABC, XYZ]