【发布时间】:2015-01-28 02:31:26
【问题描述】:
/**
* Compares this array with another array.
* <p>
* This is a requirement of the Comparable interface. It is used to provide
* an ordering for Array elements.
* @return a negative value if the provided array is "greater than" this array,
* zero if the arrays are identical, and a positive value if the
* provided array is "less than" this array.
*/
@Override
public int compareTo(Array s) {
// TODO - you fill in here (replace 0 with proper return
// value).
for (int i = 0; i < Math.min(s.size(), mSize); i++) {
if (this.mArray[i] != s.mArray[i]) {
return mArray[i] - s.mArray[i]; //FAIL HERE
}
}
return size() - s.size();
}
错误:运算符 - 未定义参数类型 Array<T>、Array。有人可以告诉我如何返回 2 个数组元素之间的差异吗?
谢谢。
【问题讨论】:
-
你的
mArray数组类型是 int 吗? -
如果Array是你自定义的类型,你应该改成别的名字,因为它是JDK中的类名。
-
私有数组
[] mArray;它可以是任何类型 -
你希望运算符
-如何应用于Array对象? -
哦,嗯,但我认为我正在做的是减去数组的元素.....
标签: java generics generic-programming subtraction