강의

멘토링

커뮤니티

Inflearn Community Q&A

jsunwoo09771172's profile image
jsunwoo09771172

asked

Java: Understanding Classes and Object-Oriented Programming

15. Object Verification

instanceof 으로 타입 체크시

Written on

·

270

1

instanceof 을 사용해서 변수의 타입을 체크하려고 하는데요.

String word = "apple";
Boolean check1 = (word instanceof String);
이렇게 하면 check1 이 true 가 뜨는데요

int num = 10;
Boolean check2 = (num instanceof int);
이렇게 하면 check2 에 true 가 안뜨고 에러가 떠서요.

왜 String, Boolean, array 다 되는데 int 만 안되는 걸 까요?

oopjava

Answer 1

2

java님의 프로필 이미지
java
Instructor

instanceof는 객체의 타입을 체크하는 것인데 int 는 기본자료형이라서, 즉 객체가 아니어서 그렇습니다.

jsunwoo09771172's profile image
jsunwoo09771172

asked

Ask a question