※ 引述《seekyou (galagala~N )》之銘言:
: public class Yikes {
: 1.public static void go(Long n){System.out.println("Long ");}
: 2.public static void go(Short n){System.out.println("Short ");}
: 3.public static void go(int n){System.out.println("int ");}
: 4. public static void main(String[] args) {
: 5. short y=6;
: 6. long z=7;
: 7. go(y);
: 8. go(z);
: 9. }
: 10.}
: 這是SCJP模擬試題,output是 int Long
: 為什麼line 8 有找到對應的方法而印出 Long,而line7就沒有呢?
: 謝謝指導
整數型別隱式轉型為int,而long由於長度大於int,
會造成精確度問題(這是javac告訴大家的...),所以會去找第一行。
可以想見,若你把第一行刪掉,則會造成編譯失敗。
--
No Dying Skills, ● - Dame! New tech...
but Lazy Users. .\)
http://www.wretch.cc/blog/hougzou ___________ ﹒ ︵ √\ ___________________
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 211.74.122.31