There is always a place in the inheritance tree where they "match", because all classes ultimately inherit from Object. But your method, being named "isInstance", looks like it should be returning a boolean value. If that's the case then it would always return true.
But no doubt I'm misunderstanding your question.
Edit: I see that Class has an isInstance() method that looks a lot like the method in your question. So that would beI will leave you to read the documentation and see if it's what you meant. [ September 13, 2007: Message edited by: Paul Clapham ]
as sometimes the best lowest common class is actually an interface. But here it is...
Thanks, I'm not sure this will do what I'm looking for, but its a hint. In this particular domain, its really instances of some flavor of fruit, but you are correct that the obvious implementation won't work well when its really an interface.
[Scott Meyers:]Anytime you find yourself writing code of the form " if the object is of type T1, then do something, but if it's of type T2, then do something else, slap yourself."
How deep is the decision tree ? It appears to me Class.isInstance(Object obj) will not support a search for commonality beyond one level deep.
I have spent enough time on all-night hair-pullers that it appears to me that you are trying to do a typing or type-resolution that would be better approached with fast editors and eager fingers than with elegance.
I realize I have used a feisty approach, and may be speaking beyond my skills ... it's just that I have too much experience wrestling with this and type resolution seems to me to be better approached by other design paradigm.