java compile error depends on whether static variable name is qualified?

Viewed 426

Why does this java program not compile:

public class xx {
    public static final Object obj;
    static {
//        obj = null;       // this compiles
        xx.obj = null;      // this doesn't
    }
}

with this error:

$ javac xx.java
xx.java:5: cannot assign a value to final variable obj
        xx.obj = null;      // this doesn't
          ^
1 error
$ javac -version
javac 1.6.0_33

when, if I replace xx.obj = null with obj = null (as alluded to in the comment) it does compile.

I thought the xx. class name prefix was more-or-less just syntax... is this a bug in the compiler or the language spec? :)

1 Answers
Related