+ 17

What is autoboxing and autounboxing in java?

What is autoboxing and autou boxing in java?Why are the used?

24th Nov 2018, 11:39 AM
Navoneel
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.
24th Nov 2018, 9:05 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 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.
24th Nov 2018, 5:10 PM
ifl
ifl - avatar
+ 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.
25th Nov 2018, 6:16 AM
Idris Tuna