For this example:
public class Foo{}
public class Bar extends Foo{}
....
void myMethod(Foo qux){
if (checkInstance(qux,Foo.class)){
....
}
}
How can I check if qux
is a instance of Foo (but not a instance of its subclass of foo)? That is:
Is there some kind of statement like instanceof
for this check? or I should use qux.getClass().equals(Foo.class)
If you have to do this, the only way would be the getClass().equals(Foo.class)
option you've suggested.
However, the goal of OO design is to allow you to treat any Foo
in the same fashion. Whether or not the instance is a subclass should be irrelevant in a normal program.