私の課題には次のコードが与えられます:
class AList<T> implements ListInterface<T> {
private T[] list; // array of list entries
private int numberOfEntries; // current number of entries in list
private static final int DEFAULT_INITIAL_CAPACITY = 25;
public AList() {
this(DEFAULT_INITIAL_CAPACITY); // call next constructor
} // end default constructor
public AList(int initialCapacity) {
numberOfEntries = 0;
// the cast is safe because the new array contains null entries
@SuppressWarnings("unchecked")
T[] tempList = (T[]) new Object[initialCapacity];
list = tempList;
} // end constructor
私の課題は、2 つの AList オブジェクトの内容が同じ場合に true を返すメソッドを作成することです。つまり、同じ数の項目があり、一方のオブジェクトの各項目は、他方のオブジェクトの対応する場所にある項目と同じです。次のメタポッド ヘッダーを使用する必要があります。
public boolean equals (Object other)
{
//my code goes here
}
これを試しましたが、うまくいきません。
public boolean equals(Object other)
{
if (Arrays.equals(this.list, other))
return true;
else
return false;
}//end equals
other は Object 型です。配列にする方法を教えてください。