Reputation: 220832
I have a source-code generator that risks generating the following type of code (just an example):
public class Outer {
public static final Object Inner = new Object();
public static class Inner {
public static final Object Help = new Object();
}
public static void main(String[] args) {
System.out.println(Outer.Inner.Help);
// ^^^^ Cannot access Help
}
}
In the above example, Inner
is ambiguously defined inside of Outer
. Outer.Inner
can be both a nested class, and a static member. It seems as though both javac
and Eclipse compilers cannot dereference Outer.Inner.Help
. How can I access Help
?
Remember, the above code is generated, so renaming things is not a (simple) option.
Upvotes: 6
Views: 135
Reputation: 500307
The following works for me (with a warning about accessing static members in a non-static way):
public static void main(String[] args) {
System.out.println(((Inner)null).Help);
}
Upvotes: 6
Reputation: 8609
How about
public static void main(String[] args) {
System.out.println(new Inner().Help);
}
Upvotes: 1