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

 

반응형

+ Recent posts