/**
*
* The Advantages and Traps of Autoboxing
*
* 優點
*
*
*
* 缺點:
*
*
*
*
* 參考
*
*/
public class M {
public static void main(String[] args) {
// 導致錯誤
Long longValue
System
System
System
System
long t
long t
// 導致效率低下
// 實驗組
t
Long counter
for (long i =
counter
}
t
System
// 實驗組
t
long counter
for (long i =
counter
}
t
System
// Integer :
// 需強制類型轉換
// 強制轉換為 int也會調用printSum(long
printSum((Integer)
// Long
printSum(
// 需強制類型轉換
// Long
printSum((Long)
// Float :
printSum(
// Double :
printSum(
}
public static void printSum(long a
System
}
public static void printSum(Long a
System
}
public static void printSum(Integer a
System
}
public static void printSum(Float a
System
}
public static void printSum(Double a
System
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26139.html