Comparing Java subclasses
<p>My app may compare instances of any two sub-classes of the same abstract parent class. I want them compared as follows:</p>

<ol>
<li>If they are different sub-classes, the parent class should do the comparison.</li>
<li>If they are the same sub-class, the sub-class should do the comparison.</li>
</ol>

<p>The classes will be compared by a TreeMap, so I have a choice of using a Comparator, or implementing Comparable (or both?).</p>

<p>I can think of several ways to do this, but they are all a bit messy and error-prone. Is there an elegant solution?</p>

<p>Thanks in advance...</p>
