姬長信(Redy)

java – 不兼容的类型:推理变量T具有不兼…


参见英文答案 > How to create ArrayList (ArrayList) from array (int[]) in Java????????????????????????????????????5个
>????????????Using Arrays.asList with int array????????????????????????????????????2个
我有以下代码
public int solution(int X, int[] A) {

    List list = Arrays.asList(A);

由于某种原因,它抛出了以下编译错误

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…)

我假设这是一个Java 8功能,但我不知道如何解决该错误