检查位置是否被占用的最佳方法是什么?如果对象的实例存在我不认为我应该用“这个== NULL” ......如何检查Java中的对象是否为空?
class Cell {
int column;
int row;
char letter;
public Cell(int column, int row, char letter) {
super();
this.column = column;
this.row = row;
this.letter = letter;
}
public boolean isEmpty() {
if (this==null) return true;
else return false;
}
}
'this'可*永远*是'null'因为它指向当前对象。你需要一些其他的方式来表明'Cell'是空的,例如另一个变量(一个布尔值,也许是?) – 2013-04-04 00:47:25
Derek Greer,http://lostechies.com/derekgreer/tag/tdd/,有一组使用TDD编写井字游戏的例子,他面临着如何渲染单元格的类似问题。但是,它在C#中。无论如何,我都会推荐它。 – 2013-04-04 01:07:59