Java 帮助 - 显示 Class 对象

Java Help - Display Class Object

我目前正在开发一款 Tic Tac Toe 游戏,我 运行 遇到了一个问题,这个问题可能很容易解决,也可能不容易解决。我正在制作一个 class 和基于方法的 Tic Tac Toe 游戏,我在多个 class 中工作,其中有很多方法。

这是我的问题:

我有一个 class 负责将所有者设置为板上的某些图块。

package game;

public class GameTile{
    /**Stores a String representing the owner "X" or "O" of a GameTile
    */
    protected String owner;
    /**Constructs a GameTile, sets owner to null by default
        */  
    public GameTile (){
        owner = null;
    }

(我有更多的代码,虽然我只展示了重要的东西,其余代码基本上声明了“X”和“O”等...)

现在我把上面的 class 打印到游戏板上 class。

package game;
/**Class for Tic Tac Toe gameboard  
    *@author Put Name Here
    */
public class GameBoard{
    
    protected static char[][] cells;
    
    /**An array of 9 GameTiles representing the TicTacToe gameboard
    */
    GameTile[] board;
    /**Constructs an empty gameboard of 9 GameTiles and fills it with unowned tiles
    */
    public GameBoard(){
        board = new GameTile[9];
        for (int i = 0; i < 9; i++) {
            board[i] = new GameTile();
        }
    }

/**This will draw the current gameboard on the screen
    */
    public void drawBoard(){
        {
            System.out.println();
                System.out.println("+---+---+---+");
                System.out.println("| " + board[0] + " | " + board[1] + " | " + board[2] + " |");
                System.out.println("+---+---+---+");
                System.out.println("| " + board[3] + " | " + board[4] + " | " + board[5] + " |");
                System.out.println("+---+---+---+");
                System.out.println("| " + board[6] + " | " + board[7] + " | " + board[8] + " |");
                System.out.println("+---+---+---+");
        }
     
    }   
}//end class

我的代码中的所有内容似乎都运行良好,尽管当我从“board”(board[1]、board[2] 等)打印任何内容时,输出总是如下所示:“game.GameTile@7de26db8

有什么方法可以让我的代码打印 GameTile() 中的字符串值?

对于您的使用方式,请覆盖您的 GameTile class 中的 toString() 方法。您现在看到的是该方法的对象 class' 版本的结果。