Beanshell not equal statement
What is if not equal
s开发者_C百科tatement in beanshell ? if this is equal :
if ("myVarValue".equals(vars.get("MY_VARIABLE")))
Use the !
unary boolean
logical complement operator:
if (!"myVarValue".equals(vars.get("MY_VARIABLE")))
References
- JLS 15.15.6 Logical Complement Operator
!
The type of the operand expression of the unary
!
operator must beboolean
orBoolean
, or a compile-time error occurs. The type of the unary logical complement expression isboolean
.At run time, the operand is subject to unboxing conversion if necessary; the value of the unary logical complement expression is
true
if the (possibly converted) operand value isfalse
andfalse
if the (possibly converted) operand value istrue
.
Another option for testing if (!something)
is to test if (something == false)
.
Related questions
- Is it bad to explicitly compare against boolean constants e.g.
if (b == false)
in Java?
精彩评论