+ 17
What is autoboxing and autounboxing in java?
What is autoboxing and autou boxing in java?Why are the used?
3 ответов
+ 17
Autoboxing and unboxing is a convenient way to auto transform primitive data type to it’s corresponding java wrapper classes and vice versa.
Autoboxing in Java:
Converting a primitive data type into an object of the corresponding wrapper class is called autoboxing. For example, converting int to Integer or converting long to Long object.
Unboxing in Java:
Converting an object of a wrapper type to its corresponding primitive data type is called unboxing.
+ 6
autoboxing is when the java compiler automatically converts a primitive type into the corresponding wrapper object.
for example,
- an int (eg 2) to an Integer.
- a character (ag 'a') to a Character
This allows to pass the primitive type to a function that expects the wrapper type as parameter, without having to do the conversion yourself, so the code is simpler to read.
+ 4
It is ralated to Wapper Classes in Java,
-Autobox
primitive —-> object
examples
char—->Character
boolean—-> Boolean
byte—->Byte
short—->Short
int—->Integer
long—->Long
float—->Float
double—->Double
Unboxing is revers of the above.