I have the following piece of code
public int solution(int X, int[] A) { List<Integer> list = Arrays.asList(A); For some reason it's throwing the following compilation error
Solution.java:11: error: incompatible types: inference variable T has incompatible bounds List list = Arrays.asList(A); ^ equality constraints: Integer lower bounds: int[] where T is a type-variable: T extends Object declared in method asList(T...)
I assume this a Java 8 feature, but I'm not sure how to resolve the error
Arrays.asList is expecting a variable number of Object. int is not an Object, but int[] is, thus Arrays.asList(A) will create a List<int[]> with just one element.
You can use IntStream.of(A).boxed().collect(Collectors.toList());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With