<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    Hi Sam,<br>
    This works in JDK 8 (I think there's even a comment in SO saying
    that). Long story short, Java 5/6/7 inference typically ignored
    inference constraints coming from lower bounds; the treatment in
    Java 8 is much more consistent - as a result this program compiles
    as you'd expect (assuming you don't use -source 7).<br>
    <br>
    Maurizio<br>
    <br>
    <div class="moz-cite-prefix">On 03/01/15 00:07, Sam Munkes wrote:<br>
    </div>
    <blockquote
cite="mid:CABjcb6VRM8xoyUeS_TeBQX-V+_Hqws_=7ia6QtyGrBWtMw0j+w@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>
          <div>
            <div>Hi Guys,<br>
              <br>
            </div>
            A colleague of mine recently posted the following question
            to StackOverflow: <a moz-do-not-send="true"
href="http://stackoverflow.com/questions/27652867/java-type-inference-with-lower-bounded-types">http://stackoverflow.com/questions/27652867/java-type-inference-with-lower-bounded-types</a><br>
            <br>
          </div>
          Does anyone on the list have insight into why the compiler
          does not infer lower bounded types?<br>
          <br>
          <span style="font-family:monospace,monospace">static class
            Test {<br>
            Â Â Â  static <T> T pick(T one, T two) {<br>
            Â Â Â Â Â Â Â  return two;<br>
            Â Â Â  }<br>
            <br>
            Â Â Â  static void testUpperBound() {<br>
            Â Â Â Â Â Â Â  List<? extends Integer> extendsInteger = new
            ArrayList<>();<br>
            <br>
            Â Â Â Â Â Â Â  // List<? extends Integer> is treated as a
            subclass of List<? extends Number><br>
            Â Â Â Â Â Â Â  List<? extends Number> extendsNumber =
            extendsInteger;<br>
            <br>
            Â Â Â Â Â Â Â  // List<? extends Number> is inferred as the
            common superclass<br>
            Â Â Â Â Â Â Â  extendsNumber = pick(extendsInteger, extendsNumber);<br>
            Â Â Â  }<br>
            <br>
            Â Â Â  static void testLowerBound() {<br>
            Â Â Â Â Â Â Â  List<? super Number> superNumber = new
            ArrayList<>();<br>
            <br>
            Â Â Â Â Â Â Â  // List<? super Number> is treated as a
            subclass of List<? super Integer><br>
            Â Â Â Â Â Â Â  List<? super Integer> superInteger =
            superNumber;<br>
            <br>
            Â Â Â Â Â Â Â  // The inferred common type should be List<?
            super Integer>,<br>
            Â Â Â Â Â Â Â  // but instead we get a compile error:<br>
            Â Â Â Â Â Â Â  <b>superInteger = pick(superNumber, superInteger);</b><br>
            <br>
            Â Â Â Â Â Â Â  // It only compiles with an explicit type argument:<br>
            Â Â Â Â Â Â Â  superInteger = Test.<List<? super
            Integer>>pick(superNumber, superInteger);<br>
            Â Â Â  }<br>
            }</span><br>
          <br>
          <br>
        </div>
        <div>Thanks<br>
          <br>
          --<br>
        </div>
        <div>Sam<br>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>