天天看点

有关short与int的重载[jase基础]

public class Test{

void max(int a, int b){

System.out.println( a>b?a:b);

}

void max(short a,short b){

public static void main(String[] args){

Test t = new Test();

t.max(3,4);

上面这个肯定是重载,问题在于何时执行max(short a,short b).

由于jvm在默认情况下都会把整数转化为int类型。因此只会执行max(int a,int b).

下面可以执行到:

short a = 3;

short b = 4;

t.max(a,b);

继续阅读