invocation order of overloaded methods in JAVA
I'm studying some exams of java and I came across with this question:
//Write the output of this program:
public static void method(Integer i) { System.out.println("Integer"); }
public static void method(short i) { System.out.println("short"); }
public static void method(long i) { System.out.println("long"); }
//...
public static void main(String []args) {
method(10);
}
//ANSWER: long
The explanation describes that for an integer literal, the JVM matches in the order: int, long, Integer. Since there is no method with int type parameter, then looks for long type; and so on.
In this explanation they only provide the order for int, long and Integer. so my question is: What is the complete order list when an integer literal is introduced in a method that is overloaded for every type (that uses integers)?
Also, what is the order for float, double etc...?(decimal values)
The complete list might be int, long, float, double, Integer, Number/Comparable/Serializable, Object.
Note: the Number, Comparable, and Serializable are ambiguous. An explicit cast would be needed to pick one of them.
链接地址: http://www.djcxy.com/p/16490.html上一篇: Spring MVC:在表单处理操作中有多个@ModelAttribute
下一篇: JAVA中重载方法的调用顺序