Wednesday, September 23, 2009

One reason to put braces in IF statement

Recently it happened to read adam-bien blog. I found the interesting explanation for why curly braces blocks are required for IF statements in Java.

Without curly brackets, you could accidentally write a semicolon after the IF-statements. The semicolon is a valid, empty statement, which will be "execute" instead of the actual (intended) one.

So either write the IF-statements with curly brackets blocks ...or carefully search for semicolons after the IF-statement.


Powered by ScribeFire.