Very interesting...
Did a few experiments and it seems that
Java will always go for the bottom-most class in a hierarchy (Object <--
String), (A <-- B <--
C). It complains about ambiguity when the parameters are not directly related.
<pre>
class A {}
class B extends A {}
class C extends B {}
class WhichOne
{
public void method(A o)
{
System.out.println("A version");
}
public void method(B o)
{
System.out.println("Bersion");
}
public void method(C o)
{
System.out.println("C version");
}
}
WhichOne x = new WhichOne();
x.method(null); // prints out "C version"
</pre>
Haven't found anything in the JLS to suggest this though... will keep looking... Oh, looks like Haining Mu found it.
[This message has been edited by JUNILU LACAR (edited June 07, 2001).]