The general form of the “if” statement looks like this:
if ( Expression ) Statement [ else Statement ]
The Expression must have boolean type. It can be a Boolean object which will be unboxed to a boolean. Requiring a boolean (in contrast to an integer) has the delightful effect of banishing the old “if (a=b)” problem, where the programmer mistakenly taps the “=” key once instead of twice, and does an assignment instead of the intended comparison, (a==b).
If that typo is written in Java, the compiler will give an error message that a boolean is needed in that context—unless a and b ...
With Safari, you learn the way you learn best. Get unlimited access to videos, live online training,
learning paths, books, interactive tutorials, and more.