2

foreach 循环完全忽略了我的 if 语句。

        for(InfoBox infoBox : mAbilities)
        {
            if(infoBox.CheckPressed(event));
            {
                //This is being outputted each time, even if the if statement returns false.
                System.out.println(infoBox.getName());
            }

            System.out.println(infoBox.CheckPressed(event));
            System.out.println(infoBox.getName());
        }
4

3 回答 3

11

您已经if用分号过早地终止了您的语句:

if(infoBox.CheckPressed(event));  // <-- remove the semicolon

这使得下面的块成为一个永远执行的独立块。

于 2012-09-16T14:52:23.103 回答
2

我想这一定是你无意中所做的事情......

if(infoBox.CheckPressed(event));

删除上述声明semicolon中的if

于 2012-09-16T14:54:18.327 回答
2

您应该从 if 语句中删除分号

if(infoBox.CheckPressed(event));
于 2012-09-16T15:11:40.423 回答