The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Specifically, when does the non-static block at the top of the class happen? What if the class is never instantiated and only contains static methods? The answer is actually in the basic tutorials, and it's called an initializer block. It gets copied into every constructor. Weird, but useful when you want to initialize stuff in every constructor but want to use code that can't be at the top with the declarations.

Re: Lazy Thursday Question: Weird Syntax You've Seen?

EDIT: Lol, I duplicated the one posted right above this post. It actually took me a ages to figure that one out, if I remember correctly. In any case, inner classes seems to be the source of many weird syntax examples .

This actually compiles. Can you see why? It is pretty easy to understand, just a case of when we humans see one thing and the compiler sees another. Had to read the explanation myself before I got it xD.

Also, this looks kind of weird, but it is valid code for returning an array.