[問題] 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