次のJavaビットがあります
if(board[i][col].equals(true))
    return false
ただし、コンパイルすると、「int を逆参照できません」というエラーが表示されます。これが何を意味するのか、誰か説明してもらえますか?
ありがとう!
次のJavaビットがあります
if(board[i][col].equals(true))
    return false
ただし、コンパイルすると、「int を逆参照できません」というエラーが表示されます。これが何を意味するのか、誰か説明してもらえますか?
ありがとう!
おそらくプリミティブ型の配列 ( int?) です。
を使え==ば大丈夫です。しかし、それがintである場合は、それを と比較していないことを確認してくださいtrue。Java は厳密に型指定されています。
equals2 つの異なるオブジェクトが等しいかどうかをテストする場合に使用します。
    // Assuming
    int[][] board = new int[ROWS][COLS];
    // In other languages, such as C and C++, an integer != 0 evaluates to true
    // if(board[i][col]) //this wont work, because Java is strongly typed.
    // You'd need to do an explicit comparison, which evaluates to a boolean
    // for the same behavior.
    // Primitives don't have methods and need none for direct comparison:
    if (board[i][col] != 0)
        return false;
    // If you expect the value of true to be 1:
    if (board[i][col] == 1)
        return false;
    // Assuming
    boolean[][] board = new boolean[ROWS][COLS];
    if (board[i][col] == true)
        return false;
    // short:
    if (board[i][col])
        return false;
    // in contrast
    if (board[i][col] == false)
        return false;
    // should be done using the logical complement operator (NOT)
    if (!board[i][col])
        return false;
    次の宣言を使用します。
boolean[][] board = initiate.getChessboard();
次の条件を使用する必要があります。
if(board[i][col] == true)
    return false;
これは次のようにも書けます:
if(board[i][col])
    return false;
これは、equalsオブジェクトにのみ適用され、ブール値はオブジェクトではなく、プリミティブ型であるためです。
がプリミティブboardの配列の場合、使用boolean
if(board[i][col] == true)
  return false;
また
if (board[i][col]) return false;
また
return !board[i][col];
    if(board[i][col])
    return false
boolean[][]比較する配列を==. また、比較を省略する== trueこともできます。