[Java] 커스텀 클래스에 Autoboxing, unboxing 적용할 수 있을까?

NCOOKIE·2025년 2월 25일
0

TIL

목록 보기
6/20

결론부터 말하자면, 안 된다.

Boxing conversion converts expressions of primitive type to corresponding expressions of reference type. Specifically, the following nine conversions are called the boxing conversions:

From type boolean to type Boolean
From type byte to type Byte
From type short to type Short
From type char to type Character
From type int to type Integer
From type long to type Long
From type float to type Float
From type double to type Double
From the null type to the null type

기본 타입의 표현식을 해당하는 참조 타입의 표현식으로 변환하는 자바의 오토박싱, 오토언박싱컴파일러가 컴파일 시 해당 코드를 자동으로 변환해주는 것이기 때문이다.

C++ 같은 언어와 같이 연산자 오버로딩도 지원하지 않기 때문에 myInteger.setValue(10)과 같이 구현해야 한다.

참고

profile
일단 해보자

0개의 댓글