JVM は、コンパイル時に呼び出すオーバーロードされたメソッドを決定します。一例があります:
public class MainClass{
public static void go(Long n) {System.out.println("takes Long ");}
public static void go(Short n) {System.out.println("takes Short ");}
public static void go(int n) {System.out.println("takes int ");}
public static void main(String [] args) {
short y = 6;
long z = 7;
go(y);
go(z);
go((Short)y);
}
}
私の理解によると、次のように出力する必要があります。
takes Short
takes Long
takes Short
...しかし、実際の出力は次のとおりです。
takes int
takes Long
takes Short
ただし、次の3つの機能がある場合:
public static void go(Integer n) {System.out.println("takes Integer");}
public static void go(Long n) {System.out.println("takes Long ");}
public static void go(Short n) {System.out.println("takes Short ");}
...そして次を使用して呼び出します:
int a= 10; and go(i); //output : takes Integer.
short
...とに違いがあるのはなぜint
ですか?