Some languages (C, C++, JavaScript, Python) allow one to use integers as booleans and vice versa:
int x;if (x) // Equivalent to: x != 0 y();
Or:
int x = 10 + (y > 10); // Equivalent to: y > 10 ? 11 : 10
However, other languages such as Java, C#, and Swift disallow this. They do not even allow explicit casting and force users to explicitly write != 0
and ? 1 : 0
to cast from integer to boolean or boolean to integer respectively.
What is the rationale for disallowing this? Allowing integers and booleans to freely convert allows certain logic to be expressed much more concisely, such as that to determine if exactly N conditions are true. So what are the drawbacks?