How do I know if an object is inherited from another object ?
Let’s say I have an abstract class A. How do I know if an object is an instance of a class inherited from A ?
boolean inherited = false;
for (Class c : instance.getClasses()) {
if (c == A.class) {
inherited = true;
break;
}
}
Does this work ? It seems a bit heavy for what I’m trying to accomplish.
instanceofshould work fine for this situation, but it does beg the question of why you’re trying to do things this way, if perhaps there’s a better more OOP solution to the underlying problem.