Why do I need to assign the result of the following conditional expression to a variable to compile it?
piece.isWhite() ? whitePieceSquares.add(getSquare(pos)) : blackPieceSquares.add(getSquare(pos));
The above does not compile as shown below:
boolean garbage = piece.isWhite() ? whitePieceSquares.add(getSquare(pos)) : blackPieceSquares.add(getSquare(pos));
List#add()returns a boolean, but I would just ignore it. Is the conditional operator simply constructed in such a way that it needs to be assigned the values returned from the functions, and the returning functions must be of the same type?
source
share