title: Java generic method cannot call another generic method with looser constraint and return its value
body: <p>I would like to do this:</p>
  
  <pre><code>&lt;T extends java.util.Date&gt; T a(@Nonnull T... dates) {
      return b(dates);  // compile error
  }
  
  &lt;T extends Comparable&lt;T&gt;&gt; T b(T... comparables) {
     return comparables[0];
  }
  </code></pre>
  
  <p>But it fails to compile unless I insert a cast within <code>a</code>:</p>
  
  <pre><code>&lt;T extends java.util.Date&gt; T a(@Nonnull T... dates) {
      return (T) b(dates);  // warning about unsafe cast in IntelliJ
  }
  
  &lt;T extends Comparable&lt;T&gt;&gt; T b(T... comparables) {
     return comparables[0];
  }
  </code></pre>
  
  <p>Interestingly, if I remove the generic from <code>a</code> it works:</p>
  
  <pre><code>java.util.Date a(java.util.Date... dates) {
      return b(dates);
  }
  
  &lt;T extends Comparable&lt;T&gt;&gt; T b(T... comparables) {
     return comparables[0];
  }
  </code></pre>
  
  <p>And if I port the original code to Kotlin, it also works (this makes me think it's a limitation of Java, and not something that is fundamentally unknowable):</p>
  
  <pre><code>fun &lt;T: java.util.Date&gt; a(dates: Array&lt;T&gt;): T {
      return b(dates);
  }
  
  fun &lt;T: Comparable&lt;T&gt;&gt; b(comparables: Array&lt;T&gt;): T {
      return comparables[0];
  }
  </code></pre>
  
  <p>My question is: <em>what is special about Java's type system that prevents this from compiling?</em> It feels to me like the Java compiler could just insert the cast behind the scenes (it is my understanding that that is how generics are implemented in other cases).</p>