I don’t know if the question can be called rhetorical, but that’s the point. Can anyone explain all the subtleties associated with curly brackets - {} (if there are any, of course)
I have an idea that if , for , methods, classes and other things use curly braces as if to define their field of influence, and in fact, when we write if { // код } , we mean that this block will be intended if'u located with him.
I am interested in, are there any features of blocks that do not have such anchoring?
For example, I cannot write sysout("bla"); outside the method sysout("bla"); (that is, right inside the class), but when I enclose the operator in a {} block {} problem disappears - magic. Why is that?
Somewhere I saw some information about this, for example, that in classes there are certain static initialization blocks and so on, like:
static { // Чудо-код } Заранее благодарю; // Или может еще как то так... Why scolds here:
public class Main { System.out.println("a"); public static void main(String[] args) { } } but not here
public class Main { { System.out.println("a"); } public static void main(String[] args) { } } The code in the block is perceived as what? What are the dramatic differences?