Why does Eclipse tell me
int a = 4;
if (a) {
//do stuff
}
is wrong, or Cannot convert from integer to boolean?
I’m used to writing things like that in C, C++, and thought Java was fine with that too. Is it how Eclipse works? Or is it how Java works? Is there any workaround?
Java, unlike C++, had a built-in boolean type from its beginnings.
Therefore, it had no need to use integers as booleans.
Disallowing implicit conversion of integer to boolean prevents the infamous
if (x = 4)bug in most cases.