javaoperatorsnot-operator

Operator ! cannot be applied to int


In C++, !1 means false which is equivalent to 0. I apply the same rule in Java, but IDE told me ! cannot be applied to int. Is there any way in Java to apply ! to int instead of just writing true or false?


Solution

  • No, not in Java.
    In java ! can operate only on boolean as negate operator, 1/0 are not considered as booleans in Java