I suppose there must be some way to use reflection to do what I want to do.
I need to be able to take a line at runtime related to a specific class, for example:
string s = "mypackage.MySuperClass"
Then I may have an object of some type. It can be one of the following:
mypackage.MySuperClass obj = new mypackage.MySuperClass();
or
mypackage.MySubClass obj2 = new mypackage.MySubClass();
or
someotherpackage.SomeOtherClass obj3 = new someotherpackage.SomeOtherClass();
What I need to do is see if the object (which is determined by its type at runtime) is equal to the string s (which is also determined at runtime using completely different means).
In the above cases, I would like obj and obj2 to be of the same type as s (since MySubClass is a subclass of MySuperClass), and obj3 will not.
Is there an easy way to do this in java? Maybe something uses instanceOf?
source share