title: Java generics compilation error "incompatible types" (in gradle but not in IDE)
body: <p>I have a problem understanding the behaviour of Java generics in the following case. </p>
  
  <p>Having some parametrised interface, <code>IFace&lt;T&gt;</code>, and a method on some class that returns a class extending this interface, <code>&lt;C extends IFace&lt;?&gt;&gt; Class&lt;C&gt; getClazz()</code> a java compilation error is produced by <code>gradle</code>, 1.8 Oracle JDK, OSX and Linux, but not by the Eclipse compiler within the Eclipse IDE (it also happily runs under Eclipse RCP OSGi runtime), for the following implementation:</p>
  
  <pre><code>public class Whatever {
    public interface IFace&lt;T&gt; {}
  
    @SuppressWarnings("unchecked")
    protected &lt;C extends IFace&lt;?&gt;&gt; Class&lt;C&gt; getClazz() {
      return (Class&lt;C&gt;) IFace.class;
    }
  }
  </code></pre>
  
  <blockquote>
    <p>➜ ./gradlew build</p>
  </blockquote>
  
  <pre><code>:compileJava
  /Users/user/src/test/src/main/java/Whatever.java:6: error: incompatible types: Class&lt;IFace&gt; cannot be converted to Class&lt;C&gt;
      return (Class&lt;C&gt;) IFace.class;
                             ^
    where C is a type-variable:
      C extends IFace&lt;?&gt; declared in method &lt;C&gt;getClazz()
  1 error
  :compileJava FAILED
  </code></pre>
  
  <p>This implementation is not a very logical one, it is the default one that somebody thought was good, but I would like to understand why it is not compiling rather than question the logic of the code.</p>
  
  <p>The easiest fix was to drop a part of the generic definition in the method signature. The following compiles without issues, but relies on a raw type:</p>
  
  <pre><code>protected Class&lt;? extends IFace&gt; getClazz() {
    return IFace.class;
  }
  </code></pre>
  
  <p>Why would this compile and the above not? Is there a way to avoid using the raw type?</p>