title: Why does Java 8's Comparator.comparing() cast the return value to Serializable?
body: <p>From JDK8's <a href="http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/java/util/Comparator.java#Comparator.comparing%28java.util.function.Function%29" rel="noreferrer">Comparator.java</a>:</p>
  
  <pre><code>public static &lt;T, U extends Comparable&lt;? super U&gt;&gt; Comparator&lt;T&gt; comparing(
          Function&lt;? super T, ? extends U&gt; keyExtractor)
  {
      Objects.requireNonNull(keyExtractor);
      return (Comparator&lt;T&gt; &amp; Serializable)
          (c1, c2) -&gt; keyExtractor.apply(c1).compareTo(keyExtractor.apply(c2));
  }
  </code></pre>
  
  <p>Notice the return statement is prefixed with an interesting cast: <code>(Comparator&lt;T&gt; &amp; Serializable)</code></p>
  
  <p>I am already aware of and (I <em>think</em>) understand:</p>
  
  <ul>
  <li>the <code>&amp;</code> operator in generic type restrictions (and can infer its purpose here),</li>
  <li>the <code>Serializable</code> interface.</li>
  </ul>
  
  <p>However, used together in the cast is baffling to me.</p>
  
  <p>What is the purpose of <code>&amp; Serializable</code> if the return type does not require it?</p>
  
  <p>I do not understand the intent.</p>
  
  <p>Follow-up to dupe/close requests: This question <a href="https://stackoverflow.com/questions/22807912/how-to-serialize-a-lambda">How to serialize a lambda?</a> does not answer question.  My question specifically notes the return type has no mention of <code>Serializable</code>, thus the source of my confusion.</p>