June 2004
Intermediate to advanced
848 pages
21h 28m
English
The autoboxing feature was introduced to Java for programmer convenience, particularly in the Collections classes that provide ready-made data structures for use on Objects. Where the intent is obvious, you no longer have to write it all out explicitly.
Just because you don't write the code explicitly, it doesn't mean the code goes away. The compiler generates actual instructions for the implied type promotions between a primitive and its object wrapper.
Those actual instructions have a performance cost at run-time, even though you don't see them at compile time. Take this autoboxing, for instance:
Integer myInt = i; // autobox!
The compiler will treat that the same way as if you had written a constructor ...
Read now
Unlock full access