In the line below where it shows return(!variable);
what does the exclamation mark do to the variable?
return(!weekday || vacation);
The double colon (::) operator, also known as method reference operator in Java, is used to call a method by referring to it with the help of its class directly. They behave exactly as the lambda expressions.
Java Identifiers All Java components require names. Names used for classes, variables, and methods are called identifiers. All identifiers should begin with a letter (A to Z or a to z), currency character ($) or an underscore (_). After the first character, identifiers can have any combination of characters.
The Java new keyword is used to create an instance of the class. In other words, it instantiates a class by allocating memory for a new object and returning a reference to that memory. We can also use the new keyword to create the array object.
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
.
The !
character is logical negation. It's formal name is, I believe, "logical not". Logically, !true == false
and !false == true
.
Like Platinum Azure said in the comments, this operator can only be applied to boolean
types.
!
means negation. Basically, "Ok, so whatever follows, if it is true, return false, if false return true." (!
will only work on booleans in Java) In this case, your return becomes:
return that it is not a weekday or that it is vacation.
It means when NOT weekday
(boolean false). !
stands for negation.
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