我有这种方法,我希望能够确定两个单元格是否相等,其中"相等"意味着它们具有相同的位置.我已经编写了这个代码,我使用它们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;
}
}
} …
Run Code Online (Sandbox Code Playgroud)