[英]Operator ! cannot be applied to int
In C++, !1
means false
which is equivalent to 0
. 在C ++中,
!1
表示false
,它等于0
。 I apply the same rule in Java, but IDE told me !
我在Java中应用了相同的规则,但是IDE告诉我
!
cannot be applied to int. 不能应用于int。 Is there any way in Java to apply
!
Java中有什么方法可以应用
!
to int instead of just writing true
or false
? 诠释而不是只写
true
还是false
?
No, not in Java. 不,不是Java。
In java ! 在java中! can operate only on boolean as negate operator, 1/0 are not considered as booleans in Java
只能以布尔值作为取反运算符进行操作,在Java中1/0不被视为布尔值
! ! only applies to Boolean values in Java, or the results of conditional statements.
仅适用于Java中的布尔值或条件语句的结果。 The closest thing you could do is
if (x == 1)
or boolean y = x == 1
. 您可以做的最接近的事情是
if (x == 1)
或boolean y = x == 1
。
Nope, operators do not work on primitive data types, with the exception of, of-course, booleans. 不,运算符不能对原始数据类型进行操作,当然,布尔值除外。 Using
!0
would simply result in an error. 使用
!0
只会导致错误。 Even though 0s and 1s can be considered boolean values, they are not in Java. 即使0和1都可以视为布尔值,但它们不在Java中。 The negation operator is only for booleans.
否定运算符仅适用于布尔值。 Something like
!0
would be: 像
!0
这样的东西是:
boolean alwaysfalse = (0 != 0);
or 要么
boolean alwaysTrue = (0 == 0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.