Boxing, UnBoxing

양혜정·2024년 1월 20일
0

Begin_java

목록 보기
14/71

Boxing

- 기본자료형으로 되어진 변수를 객체타입인 Wrapper 클래스 타입의 객체로 만들어주는 것

-> 기본자료형 (boolean, byte, short, int, long, char, float, double)
-> Wrapper 클래스(Boolean, Byte, Short, Integer, Long, Character, Float, Double)

int a1 = 10;
Integer a2 = new Integer (a1);		// Boxing
Integer a3 = Integer.valueOf(a1);	// Boxing

int b1 = 10;
Integer b2 = b1;					// Auto Boxing

UnBoxing

- Wrapper 클래스로 되어져 있는 객체를 기본자료형으로 만들어주는 것

-> Wrapper 클래스(Boolean, Byte, Short, Integer, Long, Character, Float, Double)
-> 기본자료형 (boolean, byte, short, int, long, char, float, double)

Integer a = Integer.valueOf(20);
int a4 = a.intValue();				// UnBoxing

int a5 = Integer.valueOf(20);		// Auto UnBoxing

정리

my.day04.a.wrapper -> Main_wrapper

0개의 댓글