Re: Interesting Java interview question



Maarten Bodewes <maarten.bodewes@xxxxxxxxx> wrote in news:47e68525$0$14346
$e4fe514c@xxxxxxxxxxxxxx:

<snip>
Of course, I make more frequent use of

System.out.println(new Object(){static{{}}}.toString());

since most initialization can be done within a constructor.
<snip>

Eclipse told me:

Cannot define static initializer in inner type new Object(){}

for this code:


package testpack1;
public class InnerStaticInit {
public static void main(String[] args) {
System.out.println(new Object(){static{{}}}.toString());
}
}

According to The Java Language Specification (third edition), paragraph
8.1.3, "Inner classes may not declare static initializers..."

Did I miss the joke?

.