Calling order of overloaded methods in Java

I'm studying some Java exams. I've encountered this problem:

//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 integer literals, the JVM matches in the following order: int, long, integer Since there is no method with int type parameters, find the long type; wait.

In this explanation, they only provide the order of int, long and integer So my question is: what is the complete sequential list when introducing integer literals into overloaded methods of each type (using integers)?

In addition, what is the order of float, double, etc? (decimal value)

Solution

The complete list may be int, double, integer, number / comparable / serializable, object

Note: number, comparable and serializable are ambiguous Choosing one will require a clear cast

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>