この方法では、2つのセルが等しいかどうかを判断できるようにします。ここで、「等しい」とは、それらが同じ位置にあることを意味します。このコードはinstanceof
、オブジェクトが型であることを確認してから型にキャストするためにとキャストのPosition
両方を使用して記述しましPosition
たが、何らかの理由で機能しないようです。
これが私のコードです:
public class Postion {
private int column;
private int row;
public Position (final int column, final int row) {
this.column = column;
this.row = row;
}
public int getColumn() {
return column;
}
public int getRow() {
return row;
}
public boolean equals(final Object other) {
if (other instanceof Position) {
Position position = (Position) other;
return ((column == other.getColumn()) && (row == other.getRow()));
} else {
return false;
}
}
}
このエラーコードが表示されます。実際、両方のget
メソッドのエラーコードが表示されます。
error:
cannot find symbol
return ((column == other.getColumn()) && (row == other.getRow()));
^
symbol: method getRow()
location: variable other of type Object