我有这段代码:
import java.lang.*;
class Util {
static <T extends Comparable<T>, V extends T> boolean arraysEqual(T[] x, V[] y)
{
if(x.length != y.length)
return false;
for(int i = 0; i < x.length; ++i)
if(!x[i].equals(y[i]))
return false;
return true;
}
}
class GenericsMethod {
public static void main(String args[])
{
Integer nums1[] = {1,2,3,4};
Integer nums2[] = {1,2,3,4};
System.out.println(Util.arraysEqual(nums1, nums2));
}
}
当我尝试编译时,它给了我这个错误:
error: method arraysEqual in class Util cannot be applied to given types;
System.out.println(Util.arraysEqual(nums1, nums2));
^
required: T[],V[]
found: Integer[],Integer[]
reason: inferred type does not conform to upper bound(s)
inferred: Integer
upper bound(s): Comparable<Integer>
where T,V are type-variables:
T extends Comparable<T> declared in method <T,V>arraysEqual(T[],V[])
V extends T declared in method <T,V>arraysEqual(T[],V[])
但这只发生在linux上。
$ javac -version:javac 1.8.0_111
在Windows(相同的Java版本1.8)上,它编译并运行正常。可能是什么问题?