Описание тега autoboxing
Boxing is the process of using an object to wrap a primitive value so that it can be used as a reference object; extracting a previously-boxed primitive is called unboxing. Auto(un)boxing is a form of "syntactic sugar" where the compiler automatically performs (un)boxing for you, allowing you to use value and referenced types interchangeably.
Autoboxing is a Java term where the Java compiler automatically performs boxing from a primitive value to its corresponding wrapper class. The inverse of autoboxing is called unboxing. It is considered a form of boxing in Object-oriented programming.
Examples of autoboxing:
Converting a char
to a Character
.
Double x = 3.141592
as opposed to Double x = new Double(3.141592)
. The double literal is converted to the Double
wrapper.
ArrayList<Integer> al = new ArrayList<Integer>();
al.add(100); // Autoboxing performed as an int is passed. Compiler converts to Integer.
Link to Oracle Java Documentation about autoboxing and unboxing