<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><div><br></div><div><br></div><hr id="zwchr" data-marker="__DIVIDER__"><div data-marker="__HEADERS__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>From: </b>"Maurizio Cimadamore" <maurizio.cimadamore@oracle.com><br><b>To: </b>"Archie Cobbs" <archie.cobbs@gmail.com>, "Alex Buckley" <alex.buckley@oracle.com><br><b>Cc: </b>"compiler-dev" <compiler-dev@openjdk.java.net><br><b>Sent: </b>Thursday, February 2, 2023 11:25:10 AM<br><b>Subject: </b>Re: Type parameters inside super() calls?<br></blockquote></div><div data-marker="__QUOTED_TEXT__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><p><br>
    </p>
    <div class="moz-cite-prefix">On 02/02/2023 02:04, Archie Cobbs
      wrote:<br>
    </div>
    <blockquote cite="mid:CANSoFxvzgaz4y-dNvk0N96bAoQEkZoK6gOPCYPGTtjoWE+TqSA@mail.gmail.com">
      <div>Put another way, a static method is just an instance method
        without a 'this' instance. So neither issue #1 or #2 is
        possible. So, no problem, right?<br>
      </div>
      <div dir="ltr"><br>
      </div>
      <div>You might be able to write code that looks silly, but would
        it actually be nonsensical?<br>
      </div>
      <div dir="ltr"><br>
      </div>
      <div><span style="font-family:monospace">    public class Foo<T
          extends Number> {</span></div>
      <div><span style="font-family:monospace">        public static
          toFloat(T value) {</span></div>
      <div><span style="font-family:monospace">            return
          value.floatValue();   // why not?<br></span></div>
      <div><span style="font-family:monospace">        }<br></span></div>
      <div><span style="font-family:monospace">    }<br></span></div>
      <div dir="ltr"><br>
      </div>
    </blockquote>
    <p>IMHO, this is taking it a step too far.</p>
    <p>As I said, I believe the issue stems from using the "static
      context" trick to put restriction on _expressions_ - which then
      ends up also affecting _types_.</p>
    <p>I do not think the bug has to do with "static context" being
      ill-defined. There is a big difference between using a T in a
      constructor, and using T in a static method:</p>
    <p>* when a constructor is called, you are already initializing a
      _specific_ instance, so T is _bound_;<br>
      * when a static method is called, there is no instance, so T is
      _not bound_, and has no real meaning.</p>
    <p>Allowing access to T from static method as if it was a "real
      thing"  seems like a recipe for disaster: how do we validate that
      a call to `toFloat` is correct? And, if `toFloat` returned a T,
      how do we validate that the return type is also used correctly at
      the callsite? And which synthetic cast should be generated (given
      that T not known?).</p></blockquote><div><br></div><div>C# does something like this,</div><div>  with the call, Foo<String>.toFloat(), T is equals to String</div><div>  by extension, the call Foo.toFloat() is a raw call equivalent to Foo<Number>.toFloat().<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>It works because static fields have the same behavior, you have one static field value per specialization.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>This is not how Java works, and this is great for Valhalla because it means that Java does not have to reified parametrized types (no Foo<Integer> at runtime) but only to attach the type arguments to an existing Class at runtime (Foo + erasure[Integer]). This is an important difference because it means that there is no need to define the subtyping relationship between Foo<Integer> and Foo<Double>.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;">
    <p>Maurizio<br>
    </p></blockquote><div><br></div><div>Rémi<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div></div></div></body></html>