Why doesn’t this code compile?
public boolean isOf(Class clazz, Object obj){
if(obj instanceof clazz){
return true;
}else{
return false;
}
}
Why I can’t pass a class variable to instanceof?
The
instanceofoperator works on reference types, likeInteger, and not on objects, likenew Integer(213). You probably want something likeSide note: your code will be more concise if you write
Not really sure if you need a method anymore ,though.