为什么int类型值不被装箱为Integer

Ens*_*der 4 java

public class Test {
static void test(Integer x) {
    System.out.println("Integer");
}

static void test(long x) {
    System.out.println("long");
}

static void test(Byte x) {
    System.out.println("byte");
}

static void test(Short x) {
    System.out.println("short");
}

public static void main(String[] args) {
    int i = 5;
    test(i);
}
}
Run Code Online (Sandbox Code Playgroud)

输出值为"long".

只能告诉我它为什么不是"整数",因为在Java中,int值应该是自动装箱的.

Ted*_*opp 14

当编译器有一个加宽的一个选择int到一个long或一个拳击int作为Integer时,它选择最便宜的转换:加宽到long.方法调用上下文中的转换规则在Java语言规范的第5.3节中描述,当存在多个潜在匹配时选择匹配方法的规则在第15.12.2 中描述(特别是第15.12.2.5节,但是警告说这是非常密集的阅读).