我有這種方法,我想能夠確定兩個單元格是否相等,其中「相等」意味着他們有相同的位置。我寫了這段代碼,我使用instanceof
和cast來確保我的對象的類型爲Position
,然後將它轉換爲類型Position
,但由於某種原因它似乎不起作用。錯誤當試圖使用鑄造,java
這裏是我的代碼:
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
謝謝你們!這確實有助於:) 保持支持'! ;) –