Wrapper Class?
원시 타입(Primitive Type)에 대한 객체 표현을 Wrapper class라고 한다.
Primitive Type -> Wrapper Class로 변환하는 것을 Boxing
Wrapper Class -> Primitive Type으로 변환하는 것을 Unboxing
종류
char | Character |
byte | Byte |
short | Short |
int | Integer |
long | Long |
float | Float |
double | Double |
boolean | Boolean |
특징
데이터를 수정할 수 없다.
값을 변경한다면 새로운 객체를 생성해서 저장해야한다.
예시
Integer a = new Integer(10) // deprecated
Integer b = 10; // Auto Boxing
사용하는 이유
1. Object이므로 매개변수 전달 시 레퍼런스로 전달되어 참조에 의한 변경이 가능하다.
2. Wrapper Class에 포함된 라이브러리를 사용 가능하다.(ex intValue, parseInt 등)
2. Set, Map, List 등과 같은 Collection Framework를 사용할 때 유용하다.
'자바' 카테고리의 다른 글
컬렉션 프레임워크(Collection Framework) (0) | 2022.12.09 |
---|---|
Auto Boxing/UnBoxing (0) | 2022.12.09 |
원시 타입과 참조 타입 (0) | 2022.12.09 |
추상 클래스(abstract class)와 인터페이스(interface) 의 차이점 (0) | 2022.11.30 |
오버라이딩(Overriding) 과 오버로딩(Overloading)의 차이 (0) | 2022.11.29 |