Re: Interesting Java interview question
- From: Ian Shef <invalid@xxxxxxxxxxxxx>
- Date: Tue, 01 Apr 2008 17:44:15 GMT
Maarten Bodewes <maarten.bodewes@xxxxxxxxx> wrote in news:47e68525$0$14346
$e4fe514c@xxxxxxxxxxxxxx:
<snip>
Of course, I make more frequent use of<snip>
System.out.println(new Object(){static{{}}}.toString());
since most initialization can be done within a constructor.
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?
.
- Next by Date: How do you change a LogRecord?
- Next by thread: How do you change a LogRecord?
- Index(es):