Possible Duplicate:
Anonymous code blocks in Java
I learned the other day (on SO) that
public method() {
someCode()
{
Object value = localCode();
doSomethingWith(value);
}
moreCode();
}
Is valid Java and it makes the block containing value local to that region, so value only exists in that block.
Is there any practical use for this? If not, why doesn't Java give a warning for this (silly) use of {}?