小编典典

如果即使不满足条件,语句是否始终运行,也很奇怪

java

我对if语句有一个奇怪的问题。我正在检查布尔值是否为true,是否必须运行if语句。我在很多地方都使用System.out.println布尔值,它始终为false,但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;
}

}


阅读 214

收藏
2020-10-18

共1个答案

小编典典

该行代码中有一个小的语法错误。

代替

if (checkWin());

它应该是

if (checkWin())

去除 ;

2020-10-18