Java instanceof with changing objects
Use Class.isInstance(Object)
.
How about this:
public boolean checker(Object obj) {
return obj instanceof SomeClass;
}
or if SomeClass
needs to be a parameter:
public boolean checker(Object obj, Class someClass) {
return someClass.isInstance(obj);
}
or if you want the instance to be someClass
and NOT an instance of a subclass of someClass
:
public boolean checker(Object obj, Class someClass) {
return someClass.equals(obj.getClass());
}