This is probably a larger question that you might realize.
The
Java language provides an operator "instanceof" to check the runtime type of an object.
It has been said that, in most cases, instanceof should not be used to
test for object equality as it can break the symmetric property of the equals method's equivalence relation. In this case, using the getClass method of Object is the appropriate choice. This makes a lot of sense.
The getClass example would work in a similar manner:
As an even further alternative, you may consider using something like this:
To determine if o1 is a superType pf o2. This may or may not be useful, depending on how you wish to compare o1 and o2