我对if语句有一个奇怪的问题。我检查布尔值是否为真,如果是必须运行if语句。我System.out.println很多地方的布尔值,它总是假但if语句仍然运行。有什么帮助吗?
import java.util.ArrayList;
public class GameLoop extends Thread {
private Boolean running;
private ArrayList<Meteor> meteorArrayList;
private Boolean win;
private GameScreen gameScreen;
public GameLoop(GameScreen gameScreen, ArrayList<Meteor> meteorArrayList)
{
setMeteorArrayList(meteorArrayList);
setGameScreen(gameScreen);
setRunning(true);
setWin(false);
}
@Override
public void run()
{
while (running)
{
if(checkWin());
{
System.out.println(checkWin());
gameScreen.winGame();
}
}
}
public Boolean checkWin()
{
if(getMeteorArrayList().isEmpty())
{
setWin(true);
}
else
{
setWin(false);
}
System.out.println(getWin());
return getWin();
}
public void cancel()
{
interrupt();
}
//======================GETTER EN SETTERS=============================
public Boolean getRunning() {
return running;
}
public void setRunning(Boolean running) {
this.running = running;
}
public ArrayList<Meteor> getMeteorArrayList() {
return meteorArrayList;
}
public void setMeteorArrayList(ArrayList<Meteor> meteorArrayList) {
this.meteorArrayList = meteorArrayList;
}
public Boolean getWin() {
return win;
}
public void setWin(Boolean win) {
this.win = win;
}
public GameScreen getGameScreen() {
return gameScreen;
}
public void setGameScreen(GameScreen gameScreen) {
this.gameScreen = gameScreen;
}
}
答案 0 :(得分:4)
在该行代码中有一个小的语法错误。
而不是
if (checkWin());
应该是
if (checkWin())
删除;