This relates to the Java language.
Let’s say I have we have a super class A and subclasses X and Y. I have a method in A that needs to know the type of X and Y (it’s an external library).
I have a method on A called someMethod(). My question is: in the someMethod() implementation is there a way to find out whether it is being called by X or Y?
Please let me know if this is not clear.
EDIT^2:
The concrete situation in class A looks like this.
public void delete() {
Datastore ds = Dao.instance().getDatabase();
ds.delete(this.getClass(),this.id);
}
and I’d like to be able to do X.delete() and Y.delete()
You can easily find out whether the method is called on an X or Y, using
getClass():But of course that public method could be called by any class (not just X or Y). If you need to get that information, you’ll need to get the stack trace – which may not always be reliable due to inlining etc. The right course of action will depend on why you want this information.