Hi,
When an overloaded method gets called, the compiler chooses the one with the same argument type as the argument in the call.
But what if the argument of the method call doesn'nt exactly match the arg type of any of the methods, but can be converted to match the argument type in more than one method. Which one does the compiler choose? Does it choose the closest one in the conversion chain?
Here is an example:
<pre>
public class OverLoad{
public void aMethod(int i){
System.out.println("int version : " +i);
}
public void aMethod(long l){
System.out.println("long version : " +l);
}
public static void main(
String [] args){
byte b = 2;
OverLoad ol = new OverLoad();
ol.aMethod(b);
}
}
</pre>
The output is "int version : 2"
Why exactly is it choosing aMethod(int i) ?
Thank you.
[This message has been edited by Mafalda Alabort (edited March 24, 2001).]