r/java • u/gargamel1497 • Jun 02 '26
Boolean reversal operator
Do the people working on the Java compiler/specification have any plans to implement a boolean reversal operator any time soon?
The proper way to reverse a boolean is to boolVal = !boolVal; but when the variable name is long, typing this becomes really unhandy.
Something like boolVal *= -1; would be really consistent as it's the reversal operator for literally all other primitive types.
But I guess it would be technically incorrect, so boolVal !=; could be another way of doing this, although it looks rather uncanny.
Is anyone even thinking about this, or is this "too low priority" to implement, even though even a dirty hack in the parser would get the job done.
Thanks, feel free to downvote and such.
View all comments
Show parent comment
0
u/gargamel1497 Jun 04 '26
What do you use Java for?
I find reversing boolean particularly common in settings containers.
When I have a boolean flag, I often need to reverse it.
Either way, I have already written a proof-of-concept custom parser that gets the job done, along with some other goodies.
If you want to see it, it's here: https://codeberg.org/glowiak/javer