Autoboxing
TLDR: Autoboxing is the automatic conversion of primitive data types, such as `int` or `double`, into their corresponding wrapper classes like `Integer` or `Double` in Java. Introduced in Java 5 in 2004, this feature simplifies code by allowing seamless integration of primitives with object-oriented features, such as collections or method calls requiring objects. Autoboxing improves code readability and reduces manual conversion effort.
https://en.wikipedia.org/wiki/Boxing_(computer_science)
When autoboxing occurs, the Java compiler automatically wraps the primitive value into its object equivalent. For example, adding an `int` to a `List<Integer>` automatically converts the `int` to an `Integer`. This is particularly useful when working with generic classes or collections that require objects, enabling developers to handle both primitives and objects uniformly without explicit casting or conversion.
https://docs.oracle.com/javase/tutorial/java/data/autoboxing.html
While autoboxing simplifies coding, it can introduce performance overhead due to the creation of wrapper objects and potential memory inefficiencies. For instance, repeated boxing and unboxing in loops can lead to increased garbage collection. Proper understanding and usage of autoboxing are essential to mitigate these issues, ensuring efficiency while leveraging the benefits of object-oriented programming with primitives.
https://docs.oracle.com/javase/specs/jls/se20/html/jls-5.html