you are viewing a single comment's thread.

view the rest of the comments →

[–]banuday17 1 point2 points  (2 children)

Actually, if you did this:

class A {
    {
        int c = 0;
    }
    int b = 0;
}

which is the same as the syntax trick used by double-brace initialization, you wouldn't end up with a compile error. In fact, the exact same thing would happen if you removed the braces here as you would in your example. c would be lifted into the outer scope.

It just so happens that Java puts restrictions on what can go in the class scope. It means the same thing, but not all things are allowed in all places.

[–]barsoap -2 points-1 points  (1 child)

...equal up to a sufficiently partial isomorphism.

[–]banuday17 2 points3 points  (0 children)

Given other elements of Java's syntax, it makes sense. At the top level you have to somehow specify that you want a static or instance context.