This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
Java 与 C 不同,C 允许在某些情况下将变量视为不同类型有很大的自由度,但 Java 对允许执行的操作更为严格。您的两行有问题的行是:
您需要将最后一行重新编码为:
并且,请,如果您重视那些将维护您的代码的人的理智,请不要使用以下内容:
There should never任何需要显式比较布尔值的情况。您应该选择诸如
hasSavedState
或isBroken
之类的智能名称,以便诸如:或:之
类的表达式在英语中有意义。这将大大增强代码的可读性。
无论如何,由于布尔值的显式比较会产生另一个布尔值,因此您会在哪里停止。历史悠久的反证法传统需要如下代码:
Java, unlike C which allows a great deal of latitude in treating variables as differing types in certain circumstances, is a bit more strict in what you're allowed to do. Your two problematic lines are:
You need to recode that last one as:
And, please, if you value the sanity of those who will maintain your code, don't use things like:
There should never be any need to compare a boolean explicitly. You should instead choose intelligent names like
hasSavedState
orisBroken
so that expressions like:or:
make sense in English. This will enhance the readability of your code greatly.
In any case, since the explicit comparison of a boolean results in another boolean, where would you stop. The time-honored tradition of reductio ad absurdum would require code like:
正如错误消息所述,您的代码没有任何意义;你不能写
if (boolean == int)
。您的意思可能是
if (statesSaved[i] == false)
As the error message states, your code makes no sense; you cannot write
if (boolean == int)
.You probably meant
if (statesSaved[i] == false)