[JAVA] instanseof : Object 의 타입알기

2019. 10. 13. 18:42EXPERIENCE/WEB | Java&Spring Framework

반응형

If you just want to know if an object is an instance of or extends a certain class, or implements a certain interface, you can use the instanceof keyword. 

public void myMethod(Object obj) {
    if (obj instanceof String) {
        System.out.println("It's a String");
    }
    else {
        System.out.println("It's not a String");
    }
}

 

https://coderanch.com/t/404450/java/type-object

 

how can I get the type of the object ? (Beginning Java forum at Coderanch)

 

coderanch.com

 

반응형