티스토리 뷰

프로그래밍

[JAVA] instanceof

ReturnToHome 2016. 12. 24. 21:51

Object 형이 어떤 형인지 판별할때 사용.

객체가 특정 클래스나 인터페이스로부터 생성된 객체인지를 판별 해주는 연산자.

 

형식) 객체참조변수 instanceof Type

 

ex)

 

public class TestA {}

public class TestB extends TestA{}

public class TestC extneds TestB{}

 

각각 testA, testB, testC 로 객체 생성하였다 했을 시

testA instanceof testA > true

testA instanceof testB > false

testA instanceof testC > false

testB instanceof testA > true

testB instanceof testB > true

testB instanceof testC > false

testC instanceof testA > true

testC instanceof testB > true

testC instanceof testC > true

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함