tags:

views:

231

answers:

2

Granted he didn't show us actual code here, just mentioned it, I found it extremely bizarre.

For example, according to what he said this is valid Java:

public class Person
{
    String Name;
    int Age;

    {
        //These two braces just chilling together - VALID? :O
    }
}
A: 

Sure - Give it a try. It is valid in most languages. Well, most that I have developed in. Just to make sure I tried it in the code I have open right now.

Rob Goodwin
+13  A: 

Yes - it's the instance initializer. You can also use it along with anonymous subclasses for Double-Brace Initialization.

gustafc
Not with a semi-colon in between. The { } are just a scope definition.
vfilby
Nope, not when it's floating around in the class body like that - it's an empty instance initializer. Inside methods, then yes, it's a scope definition.
gustafc
@vfilby: No, if it's a block within a class but not within a method or constructor, it's an instance initializer.
Jon Skeet
My bad, didn't look closely enough at the example. Thanks guys.
vfilby