Should Comparable ever compare to another type? : <p>I'm wondering if there's ever a valid use case for the following:</p>

<pre><code>class Base {}

class A implements Comparable&lt;Base&gt; {
    //...
}
</code></pre>

<p>It seems to be a common pattern (see <a href="https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html" rel="noreferrer">Collections</a> for a number of examples) to accept a collection of type <code>T</code>, where <code>T extends Comparable&lt;? super T&gt;</code>.</p>

<p>But it seems technically impossible to fulfill the contract of <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Comparable.html#compareTo-T-" rel="noreferrer"><code>compareTo()</code></a> when comparing to a base class, because there's no way to ensure that another class doesn't extend the base with a contradictory comparison. Consider the following example:</p>

<pre><code>class Base {
    final int foo;
    Base(int foo) {
        this.foo = foo;
    }
}

class A extends Base implements Comparable&lt;Base&gt; {
    A(int foo) {
        super(foo);
    }
    public int compareTo(Base that) {
        return Integer.compare(this.foo, that.foo); // sort by foo ascending
    }
}

class B extends Base implements Comparable&lt;Base&gt; {
    B(int foo) {
        super(foo);
    }
    public int compareTo(Base that) {
        return -Integer.compare(this.foo, that.foo); // sort by foo descending
    }
}
</code></pre>

<p>We have two classes extending <code>Base</code> using comparisons that don't follow a common rule (if there were a common rule, it would almost certainly be implemented in <code>Base</code>). Yet the following broken sort will compile:</p>

<pre><code>Collections.sort(Arrays.asList(new A(0), new B(1)));
</code></pre>

<p>Wouldn't it be safer to only accept <code>T extends Comparable&lt;T&gt;</code>? Or is there some use case that would validate the wildcard?</p>
