Learn Java Programming - Autoboxing Tutorial

Опубликовано: 31 Август 2015
на канале: Daniel Ross
1,100
19

In my Primitive Wrapper Classes Tutorial I discussed the basics of how the wrapper classes work.
Quick refresher ...
int i = 41;
Integer ref = new Integer(i); // box the primitive int type value into an Integer object
i = ref.intValue(); // unbox the int value from the Integer object

Based on the code sample from above, it would become quite tedious manually exchanging values from primitive types to objects and vice-versa. Say hello to the concept of autoboxing and auto-unboxing! Java autoboxing automatically encapsulates primitive data types into object state for us, Java also does the dirty work by auto-unboxing object state into a primitive value. Autoboxing opens a whole new world of possibilities, especially in future concepts that utilize anything related to Generics. Don't worry about Generics yet, I will discuss them when the time is right.
Here is the same thing as above with autoboxing ...
Integer ref = 41; // autobox the primitive int type value into an Integer object
int i = ref; // auto-unbox a primitive int value from an Integer object


На этой странице сайта вы можете посмотреть видео онлайн Learn Java Programming - Autoboxing Tutorial длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Daniel Ross 31 Август 2015, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 1,100 раз и оно понравилось 19 зрителям. Приятного просмотра!