I was cleaning up code and changing all access to static member such that they are qualified by the class in which they are defined. This, however, lead to the following problem which is puzzling me.
I have a class with a nested class inside. In the annotation on this nested class I refer to a private static final field in the surrounding class. When doing this without qualification (as in the annotation on class D, below) this works. However, when adding the class qualifier (as in the annotation on class C) the compiler tells the field (v below) is not visible.
public class VisibilityTest {
@interface A {
int f();
}
@A(f = VisibilityTest.v) //fails
private static class C {
int c = VisibilityTest.v; //works
}
@A(f = v) //works
private static class D {
int d = VisibilityTest.v; //works
}
private final static int v = 5;
}
In both cases the variable refers to the same field, so why does this happen?