[问题] Number Wrapper & method overloading

楼主: uopsdod (pcman)   2017-02-15 19:12:21
public class Prac extends Test2{
public static void go(Long n){
System.out.println("Long ");
}
public static void go(Short n){
System.out.println("Short ");
}
public static void go(int n){
System.out.println("int ");
}
public static void main(String[] args) throws IOException{
short y = 6;
long z = 7;
go(y);
go(z);
}
}
作者: kyleJ (资工人)   2017-02-15 22:36:00
main里面的short是基本型态 比起自动装箱 Java会先寻找自动宽化后符合的型态吧
楼主: uopsdod (pcman)   2017-02-19 18:41:00
原来是这样,了解了感谢!

Links booklink

Contact Us: admin [ a t ] ucptt.com