What is Auto-boxing and Unboxing, and does it impact performance?


Autoboxing is the process of automatic conversion (by the Java compiler) from the primitive type to the corresponding object type (wrapper class of the primitive type). Unboxing is the reverse process, the conversion from the object type to the primitive type. Some primitive-object type pairs are (int, Integer), (long, Long), (double, Double) etc.

Since there's additional work required to execute them, both autoboxing and unboxing have an impact on the performance, so the developer should be careful and identify the points where autoboxing/unboxig happens to take care of some optimizations if needed.

0 answers