I'd like to confirm the meaning of !=
before a boolean expression in a control statement means the opposite:
For example:
if (!networkConnected())
Does that mean "if the network is not connected"?
Yes it does mean the logical opposite. It works even with equals operator.
Assuming your method return a basic bool type
// means the Network is NOT connected
if (!NetworkConnected())
This is equivalent to
if (NetworkConnected() != true)
So logically means
if (NetworkConnected() == false)
Now assuming you method return a Boolean (indeed a real object), this means
// means the Network is NOT connected
if (! Boolean.TRUE.equals(NetworkConnected());
or
if (Boolean.FALSE.equals(NetworkConnected());
Yes, it's boolean negation
So
true == true
!true == false
!!true == true
!!!true == false
Likewise with false
!false == true
The actual name for this unary operator is the Logical Complement Operator
which inverts the value of a boolean
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With