What does an exclamation mark mean in Java?
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());
Meaning of ! in Java syntax
The !
is a boolean NOT operator, defined in Section 15.15.6 of the Java Language Specification. It makes true
false
and false
true
. So what that return statement is doing is returning a boolean which will be true
if either weekday
is false
("not weekday") or (||
) vacation
is true
. It will be false
if weekday
is true
and vacation
is false
.
What does an exclamation mark before a variable mean in JavaScript
!
is the logical not operator in JavaScript.
Formally
!expression
is read as:
- Take
expression
and evaluate it. In your case that'svariable.onsubmit
- Case the result of that evaluation and convert it to a boolean. In your case since
onsubmit
is likely a function, it means - if the function is null or undefined - return false, otherwise return true. - If that evaluation is true, return false. Otherwise return true.
In your case
In your case !variable.onsubmit
means return true if there isn't a function defined (and thus is falsy), otherwise return false (since there is a function defined).
Simply put - !variable
means take the truth value of variable
and negate it.
Thus, if (!variable) {
will enter the if
clause if variable is false
(or coerces to false)
In total
if (!variable.onsubmit || (variable.onsubmit() != false)) {
Means - check if variable.onsubmit
is defined and truthy (thus true), then it checks if calling onsubmit
returns a result that coerces to true. In a short line it checks if there is no onsubmit
or it returns true.
Next time, how do I find this myself?
- MDN has a list of operators here.
- The language specification specifies such operators, though being the official specification it does contain some jargon which might be hard to understand.
What does the exclamation mark before class path do in ProGuard?
It means the same thing that ! means in many other programming languages. It negates the selection that follows. So in your example, the keep directive will apply to everything that is not in the following package/class selection.
Related Topics
Why Doesn't Java Allow Generic Subclasses of Throwable
Spring-Batch Without Persisting Metadata to Database
Connecting an Input Stream to an Outputstream
Java Enum and Additional Class Files
Why Is an Instance Variable of the Superclass Not Overridden by a Subclass
Updating UI from Different Threads in Javafx
Why Is Javafx Is Not Included in Openjdk 8 on Ubuntu Wily (15.10)
How to Unmap a File from Memory Mapped Using Filechannel in Java
Java, Simplified Check If Int Array Contains Int
Run Exe Which Is Packaged Inside Jar File
Sending Mail Attachment Using Java
Is It Safe to Construct Swing/Awt Widgets Not on the Event Dispatch Thread
Jpa/Hibernate Native Queries Do Not Recognize Parameters
Why Does Int Num = Integer.Getinteger("123") Throw Nullpointerexception