Extending interfaces and conversion errors in Java
<p>I'm trying to implement a "PriorityThreadPoolExecutor".</p>

<p>So I declare the Executor: </p>

<pre><code>static ThreadPoolExecutor threadPool =  
                new ThreadPoolExecutor(2, 100, 100, TimeUnit.SECONDS, queue); 
</code></pre>

<p>And the key for the prioritization is the queue paramether. Basically I need a PriorityBlockingQueue so I use the constructor:</p>

<pre><code>PriorityBlockingQueue(int initialCapacity, Comparator&lt;? super E&gt; comparator);
queue = new PriorityBlockingQueue&lt;mRunnable&gt;(10,
        new Comparator&lt;mRunnable&gt;() {

            @Override
            public int compare(mRunnable lhs, mRunnable rhs) {
                return rhs.getPriority()-lhs.getPriority();
            }
        });
</code></pre>

<p>Where the mRunnable is:</p>

<pre><code>public interface mRunnable extends Runnable {
    public int getPriority();
}
</code></pre>

<p>But here the compiler complains:</p>

<pre><code>Type mismatch: cannot convert from PriorityBlockingQueue&lt;mRunnable&gt; 
       to PriorityBlockingQueue &lt;Runnable&gt;
</code></pre>

<p>I do not understand why is this error happening when mRunnable extends Runnable.</p>

<p>I could patch it changing the comparator:</p>

<pre><code>new Comparator&lt;Runnable&gt;() {

    @Override
    public int compare(Runnable lhs, Runnable rhs) {
        if (lhs instanceof mRunnable &amp;&amp; rhs instanceof mRunnable){
        return ((mRunnable)rhs).getPriority()-((mRunnable)lhs).getPriority();
        }
        return 0;
    }
});
</code></pre>

<p>But this is a ugly sollution imho.</p>

<p>Can you explain why is the Type mismatch is happening? Thanks</p>
