-
카테고리
-
세부 분야
프로그래밍 언어
-
해결 여부
해결됨
래퍼 클래스 - 참조형 기본형 비교
24.05.03 19:04 작성 조회수 65
0
public class WrapperClassMain {
public static void main(String[] args) {
Integer i = new Integer(10);
Integer in = new Integer(10);
Integer integerObj = Integer.valueOf(10); //-128~ 127 자주 사용하는 숫자 값 재사용
System.out.println("내부 값 읽기");
int intValue = i.intValue();
System.out.println(intValue);
System.out.println(i == intValue); //true
System.out.println(i == integerObj); //false
System.out.println(i == in); //false
System.out.println(in == intValue); //true
}
}
래퍼 클래스는 인스턴스의 참조값을 비교한다고 했는데, (i==intValue) 이 부분에서 참조형과 기본형을 비교하는 부분에서는 왜 true가 나오나요?
답변을 작성해보세요.
답변 1