title: Why does Function.identity() break type reification but t -> t does not?
body: <p>Answers found at <a href="https://stackoverflow.com/q/28032827/14731">Java 8 lambdas, Function.identity() or t-&gt;t</a> seem to imply that <code>Function.identity()</code> is almost always equivalent to <code>t -&gt; t</code>. However, in the testcase seen below, replacing <code>t -&gt; t</code> by <code>Function.identity()</code> results in a compiler error. Why is that?</p>
  
  <pre><code>public class Testcase {
  
      public static &lt;T, A, R, K, V&gt; Collector&lt;T, A, R&gt; comparatorOrdering(
              Function&lt;? super T, ? extends K&gt; keyMapper,
              Function&lt;? super T, ? extends V&gt; valueMapper,
              Comparator&lt;? super K&gt; keyComparator,
              Comparator&lt;? super V&gt; valueComparator) {
          return null;
      }
  
      public static void main(String[] args) {    
          Map&lt;Integer, String&gt; case1 = Stream.of(1, 2, 3).
                  collect(comparatorOrdering(t -&gt; t, t -&gt; String.valueOf(t),
                          Comparator.naturalOrder(), Comparator.naturalOrder()));
          Map&lt;Integer, String&gt; case2 = Stream.of(1, 2, 3).
                  collect(comparatorOrdering(Function.identity(), t -&gt; String.valueOf(t),
                          Comparator.naturalOrder(), Comparator.naturalOrder()));
      }
  }
  </code></pre>
  
  <p>Case 1 compiles just fine but case 2 fails with:</p>
  
  <pre><code>method comparatorOrdering in class Testcase cannot be applied to given types;
                  collect(comparatorOrdering(Function.identity(), t -&gt; String.valueOf(t),
    required: Function&lt;? super T#1,? extends K&gt;,Function&lt;? super T#1,? extends V&gt;,Comparator&lt;? super K&gt;,Comparator&lt;? super V&gt;
    found: Function&lt;Object,Object&gt;,(t)-&gt;Strin[...]Of(t),Comparator&lt;T#2&gt;,Comparator&lt;T#3&gt;
    reason: inferred type does not conform to upper bound(s)
      inferred: Object
      upper bound(s): Comparable&lt;? super T#4&gt;,T#4,Object
    where T#1,A,R,K,V,T#2,T#3,T#4 are type-variables:
      T#1 extends Object declared in method &lt;T#1,A,R,K,V&gt;comparatorOrdering(Function&lt;? super T#1,? extends K&gt;,Function&lt;? super T#1,? extends V&gt;,Comparator&lt;? super K&gt;,Comparator&lt;? super V&gt;)
      A extends Object declared in method &lt;T#1,A,R,K,V&gt;comparatorOrdering(Function&lt;? super T#1,? extends K&gt;,Function&lt;? super T#1,? extends V&gt;,Comparator&lt;? super K&gt;,Comparator&lt;? super V&gt;)
      R extends Object declared in method &lt;T#1,A,R,K,V&gt;comparatorOrdering(Function&lt;? super T#1,? extends K&gt;,Function&lt;? super T#1,? extends V&gt;,Comparator&lt;? super K&gt;,Comparator&lt;? super V&gt;)
      K extends Object declared in method &lt;T#1,A,R,K,V&gt;comparatorOrdering(Function&lt;? super T#1,? extends K&gt;,Function&lt;? super T#1,? extends V&gt;,Comparator&lt;? super K&gt;,Comparator&lt;? super V&gt;)
      V extends Object declared in method &lt;T#1,A,R,K,V&gt;comparatorOrdering(Function&lt;? super T#1,? extends K&gt;,Function&lt;? super T#1,? extends V&gt;,Comparator&lt;? super K&gt;,Comparator&lt;? super V&gt;)
      T#2 extends Comparable&lt;? super T#2&gt;
      T#3 extends Comparable&lt;? super T#3&gt;
      T#4 extends Comparable&lt;? super T#4&gt; declared in method &lt;T#4&gt;naturalOrder()
  </code></pre>
  
  <p>My environment is Windows 10, 64-bit, Oracle JDK build 1.8.0_92-b14.</p>
  
  <p><strong>UPDATE</strong>: Seeing as this compiles under ecj, I have a follow-up question: Is this a bug in <code>javac</code>? What does the JLS have to say about this case?</p>