![[기술 면접] 11. int와 Integer는 무엇이 다르나요? 1 제목을 입력해주세요 복사본 20 001](http://allhoneytip.com/wp-content/uploads/2023/09/제목을-입력해주세요__복사본-20-001-300x300-optimized.png)
저번 시간에 이어, 이번엔 int와 Integer의 차이에 대한 면접 질문을 간단하게 알아보겠습니다.
![[기술 면접] 11. int와 Integer는 무엇이 다르나요? 2 Java Generic 타입에 대해서 설명해주세요.](http://allhoneytip.com/wp-content/uploads/2023/07/image-59-1024x512-optimized.png)
Q: int와 Integer는 무엇이 다르나요?
int는 변수의 타입이고, Integer는 기본 타입의 데이터를 객체로 다루기 위해 사용하는 래퍼 클래스(Wrapper class)입니다.
int
- 산술 연산 가능
- null 초기화 불가능
Integer
- unboxing 해야만 산술 연산 가능
- unboxing: wrapper class -> primitive type 변환. 즉, Integer to int
- null값 처리 가능
// Valid int n = 20; // Valid Integer n = 45; // Valid Integer.parseInt("10"); // Not Valid, int에는 String Casting 불가능. int.parseInt("10");
마치며
이번 시간엔, int와 Integer의 차이에 대해서 알아보았습니다.
다음 시간엔, volatile 키워드가 무엇인지에 대한 면접 질문을 알아보겠습니다.
![[기술 면접] 11. int와 Integer는 무엇이 다르나요? 2 Java Generic 타입에 대해서 설명해주세요.](http://allhoneytip.com/wp-content/uploads/2023/07/image-59-1024x512-optimized.png)
답글 남기기