Reputation: 7985
It is just my curiosity whether I can do something like
private static boolean and = &&;
I wonder whether a "logical and operator" can be assigned to a "boolean variable".
P.S. I can't compile the sentence, because it already gave an error. Since variable initialization requires tokens and && is not a token.
Upvotes: 1
Views: 957
Reputation: 1233
Here is an example using English grammar, the way I see it:
"And" and "True" are different parts of speech. "True" is an adjective, so you can say, "That is true." "And" is a conjunction, so it does not make sense to say "That is and."
Same thing with &&
and true
. &&
is an operator "part of speech," whereas true
is a value "part of speech." Because of this, it doesn't make sense to set a boolean
value to an operator. Perhaps something like this could be done, if instead of boolean and = &&
you could type BooleanOperator and = &&
; however, there is no such type or functionality in Java (see Chris's answer about C).
Upvotes: 1
Reputation: 16215
You can't do this in Java. If you have your heart set on doing something like this, try using the preprocessor command #define
in C or C++.
Beware though - this is NOT recommended as you'll have a lot of trouble debugging and finding other developers to work on code with you.
You may even end up with your own entry on TheDailyWTF (like this, this, this, this, or this)
Upvotes: 2
Reputation:
For years people have wanted sentence like programming. If you can make a language that does that, then awesome! However java cannot be converted to sentence like programming. Perhaps you could write a string modifying class that assigns certain words to other characters that it would then input into whatever text editor you are using. Good luck debugging though!
Upvotes: 0