Dan, I think you�re wrong. Just because there is a conversion from any other type to String, it doesn�t mean that it will be used all the time. What happens in bani�s problem is that the compiler chooses the most specific method to run, like this:
JLS 15.12.2.2:
The precise definition is as follows. Let m be a name and suppose that there are two declarations of methods named m, each having n parameters. Suppose that one declaration appears within a class or interface T and that the types of the parameters are T1, . . . , Tn; suppose moreover that the other declaration appears within a class or interface U and that the types of the parameters are U1, . . . , Un. Then the method m declared in T is more specific than the method m declared in U if and only if both of the following are true:
T can be converted to U by method invocation conversion.Tj can be converted to Uj by method invocation conversion, for all j from 1 to n.
here�s an example from the same section of the jls that shows this exact thing:
Consider the example:
This example produces an error at compile time. The problem is that there are two declarations of test that are applicable and accessible, and neither is more specific than the other. Therefore, the method invocation is ambiguous.
If a third definition of test were added:
static void test(ColoredPoint p, ColoredPoint q) {
System.out.println("(ColoredPoint, ColoredPoint)");
}
then it would be more specific than the other two, and the method invocation would no longer be ambiguous.
So since String is more specific than Object, because String is a sub-class of Object, the compiler will choose the String version method.
In srinivas� example, since the argument is an int it chooses the int version, following the same logic.
Hope that helps, if you have anymore doubts please let me know.
Francisco
[ July 16, 2002: Message edited by: Francisco A Guimaraes ]