Public class eggs {
Int Dox (long X, long y ){
Return 1;
}
Int Dox (long... x ){
Return 2;
}
Int Dox (integer x, integer y ){
Return 3;
}
Int Dox (number N, number m ){
Return 4;
}
//
// Int doX (long n, long m ){
// Return 5;
//}
Void go (){
Short s = 7;
System. out. print (doX (s, s) + "");
System. out. println (doX (7,7 ));
}
/**
* @ Param args
*/
Public static void main (string [] ARGs ){
New eggs (). Go ();
}
}
Running result:
4 3
Public class eggs {
Int Dox (long X, long y ){
Return 1;
}
Int Dox (long... x ){
Return 2;
}
Int Dox (integer x, integer y ){
Return 3;
}
Int doX (Number n, Number m ){
Return 4;
}
Int doX (long n, long m ){
Return 5;
}
Void go (){
Short s = 7;
System. out. print (doX (s, s) + "");
System. out. println (doX (7,7 ));
}
/**
* @ Param ARGs
*/
Public static void main (string [] ARGs ){
New eggs (). Go ();
}
}
Running result
5 5
Conclusion:
The first code Description: The short type can be automatically packaged into the short type, and then the Dox (number, number) method is called because short is a subclass of number. However, the short type cannot be converted to the long type, and then automatically wrapped into the long type. Of course, from the second code, we can see that in the case of the existence of the Oracle (Long, long), we still give priority to the call of the Oracle (Long, long) method.
As for the Dox (long... x) method, it should be the last called, that is, the lowest priority.
Package scjp. test;
Public class eggs {
Int Dox (long X, long y ){
Return 1;
}
Int doX (long... x ){
Return 2;
}
Int doX (Integer x, Integer y ){
Return 3;
}
// Int doX (Number n, Number m ){
// Return 4;
//}
//
// Int doX (long n, long m ){
// Return 5;
//}
Void go (){
Short s = 7;
System. out. print (doX (s, s) + "");
System. out. println (doX (7,7 ));
}
/**
* @ Param args
*/
Public static void main (String [] args ){
New eggs (). Go ();
}
}
Running result:
2 3