public class TestOverload {
public void go(Short n){
System.out.println("Short");
}
public void go(int n){
System.out.println("int");
}
public static void main(String[] args) {
TestOverload t = new TestOverload();
short x = 6;
t.go(x);
}
}
为什么输出的是int
jdk5.0不是可以自动装箱吗 为什么不选择装箱而是选择由short到int的类型自动提升

解决方案 »

  1.   


    public class TestOverload { 
    public void go(short n){ 
    System.out.println("Short"); 

    public void go(int n){ 
    System.out.println("int"); 

    public static void main(String[] args) { 
    TestOverload t = new TestOverload(); 
    short x = 6; 
    t.go(x); 

    } 注意大小写,是short,不是Short,Short是short的封装类
      

  2.   

    我估计你没明白楼主的意思,看下面的代码:如果我把后面两个注释掉t.go(x)将会输出"Short",如果我只留中间的那个,那么输出时"int",如果只留最后一个,输出则是"short"。public void go(Short n){ 
    System.out.println("Short"); 


    public void go(int n){ 
    System.out.println("int"); 


    public void go(short n){ 
    System.out.println("short"); 

      

  3.   

    楼主啊 怎么说你呢?你真是太粗心了,这样可不行,程序员可是要很仔细的人,要注意点了,short要小写的。
    public class TestOverload { 
    public void go(short n){ 
    System.out.println("Short"); 

    public void go(int n){ 
    System.out.println("int"); 

    public static void main(String[] args) { 
    TestOverload t = new TestOverload(); 
    short x = 6; 
    t.go(x); 


      

  4.   

    我想了一下 有可能是Short是个封装的类,其实就是一个类,它不是基本的数据类型,而你用的测试是数字6
    它自然不属于Short这个封装类的对象了,调用时它就调用了下面的方法