解决方法
使用集合时,自动装箱也会起作用.如sun的java文档中所述:@H_502_5@
Collections can only hold object references,so you have to Box primitive values into the appropriate wrapper class. … When you take the object out of the collection,you get the Integer that you put in; if you need an int,you must unBox the Integer using the intValue method. All of this Boxing and unBoxing is a pain,and clutters up your code. The autoBoxing and unBoxing feature automates the process,eliminating the pain and the clutter. @H_502_5@
So when should you use autoBoxing and unBoxing? Use them only when there is an “impedance mismatch” between reference types and primitives,for example,when you have to put numerical values into a collection. It is not appropriate to use autoBoxing and unBoxing for scientific computing,or other performance-sensitive numerical code. An Integer is not a substitute for an int; autoBoxing and unBoxing blur the distinction between primitive types and reference types,but they do not eliminate it. @H_502_5@