Possible Duplicate:
What does two consecutive blocks of code {}{} do?
I am reworking a very old Java application and have observed that the original developer used a lot of compound statements within methods that are not part of any conditional or looping logic.
Example pseudocode:
{
Object a = new Object();
a.setAttribute();
}
{
Object b = new Object();
b.setAttribute();
}
Is this just a style preference or am I missing something?
Local variables declared inside one block are not visible in any others, so it’s handy for things like code generation where you don’t need to worry about name clashes between different blocks of code. I wouldn’t generally use this technique in hand-written code.