What are the rules Java uses to resolve dotted identifiers?
For example:
import Foo.Bar;
class Foo
{
public static class Bar
{
};
};
Now, Foo.Bar
can refer to either the imported class Bar
or the one defined in the source code. How is this kind of ambiguity resolved?
I have tried this one case so I know what happens in practice, but I'm looking for more than that; I want to know the underlying rules. For example, if Foo.Bar
exists in the source file, can I still refer to the imported class Foo.Bar.Baz
? What if Foo.Bar
is a package and also a class? If the compiler can't find Foo.Bar
in the closest Foo
, does it just give up, or does it keep looking for other Foo
s until it either runs out or finds one that matches?
(Incidentally, I have found the relevant bit in the language specification. It doesn't help much...)