I have a question about the meaning (evaluation) of Boolean variables in return statements in Java.
I know that:
if (var) { ... }
i
A Java conditional requires a boolean value. If you can put it into an if statement, it's already a boolean, and requires no further fiddling if what you want is a boolean.
Indeed, constructs like value == true
can be tricky. I don't offhand remember the promotion rules in Java, but in C++ a bool can be promoted to an int, with false becoming 0 and true becoming 1. Therefore, int a = 2; if (a)
and int a = 2; if (a == true)
will do different things.