A
Andreas Leitgeb
Ok, I know that this breaks conventions and common sense, but
just for the sake of understanding the JLS...
--- snip foo/Foo.java ---
package foo;
public class Foo {
public static String bad_name = "boo!"; // bad name for a field
public static class bad_name { // even worse, because lower case
public static void foo() { }
}
static {
bad_name.foo(); // doesn't work, because field obscures type - Ok.
foo.Foo.bad_name.foo(); // fqn doesn't work, either, but shouldn't it?
}
}
--- end snip ---
JLS (6.4.2. Obscuring) has to say about this case:
- If a field name obscures a type name, then a
fully qualified name for the type can be used
unless the type name denotes a local class (§14.3).
("bad_name" isn't a local class, so the "unless"-part doesn't apply.)
Even if the field was non-static, the compiler still doesn't use
the type but rather complains about unavailability of the field,
even with the fqn.
PS: suggesting "rename the field or (better) the type" as a solution
is really missing the point of this post.
just for the sake of understanding the JLS...
--- snip foo/Foo.java ---
package foo;
public class Foo {
public static String bad_name = "boo!"; // bad name for a field
public static class bad_name { // even worse, because lower case
public static void foo() { }
}
static {
bad_name.foo(); // doesn't work, because field obscures type - Ok.
foo.Foo.bad_name.foo(); // fqn doesn't work, either, but shouldn't it?
}
}
--- end snip ---
JLS (6.4.2. Obscuring) has to say about this case:
- If a field name obscures a type name, then a
fully qualified name for the type can be used
unless the type name denotes a local class (§14.3).
("bad_name" isn't a local class, so the "unless"-part doesn't apply.)
Even if the field was non-static, the compiler still doesn't use
the type but rather complains about unavailability of the field,
even with the fqn.
PS: suggesting "rename the field or (better) the type" as a solution
is really missing the point of this post.