<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <font size="4" face="monospace">While I totally understand why you
      would want to do that, I don't see the connection between pattern
      assignment and extending the type system to permit denotation of
      quantified or existential types?  I don't see any patterns in your
      example, only type manipulation.<br>
      <br>
      What you're saying is that you'd like a conversion from
      Foo<?> to `\exist T . <br>
      Foo<T>`.  This is understandable, as wildcards are basically
      existentials already, and is just as safe as the the trick of
      calling an out-of-line generic method.  <br>
      <br>
      But I just don't see the connection with pattern assignment?  It
      seems like what you really want is "generic variables", to go
      along with generic methods and classes?<br>
      <br>
      <br>
      <br>
    </font><br>
    <div class="moz-cite-prefix">On 1/13/2026 5:56 PM, Archie Cobbs
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:CANSoFxvaVo1wFdfx-DjZOw=AMG0T6XcKrmgta6vPmvdWPdVkgA@mail.gmail.com">
      
      <div dir="ltr">
        <div dir="ltr">
          <div>[ This is in reply to <a href="https://mail.openjdk.org/pipermail/amber-spec-experts/2026-January/004306.html" moz-do-not-send="true" class="moz-txt-link-freetext">https://mail.openjdk.org/pipermail/amber-spec-experts/2026-January/004306.html</a>
            on amber-spec-experts. ]</div>
          <div><br>
          </div>
          <div>Hi Gavin,</div>
          <div><br>
          </div>
          The "Pattern Assignment" and "Constant Patterns" ideas
          sound good to me. The "Pattern Assignment" idea is a natural
          way to extend pattern matching, which is motivated by the
          frequent need to declare variables to access the "variable
          components" in an instance of some object type.</div>
        <div dir="ltr"><br>
        </div>
        <div dir="ltr">My question is: Wouldn't the same motivation
          apply to generic type parameters as well?</div>
        <div><br>
        </div>
        <div>Here's a trivial example. Suppose we have this class:</div>
        <div><span style="font-family:monospace"><br>
          </span></div>
        <div><span style="font-family:monospace">    public record
            Property<T>(T value) {<br>
                    boolean has(T t) {<br>
                        return t == value;<br>
                    }<br>
                }<br>
          </span><br>
        </div>
        <div>and we want to write a method to check that a list of <span style="font-family:monospace">Property</span>'s are
          well-behaved.</div>
        <div><br>
        </div>
        <div>Here's what we'd LIKE to do, which is use "Pattern
          Assignment" for the generic type variable:</div>
        <div><br>
        </div>
        <div><span style="font-family:monospace">    public void
            verifyHas(List<Property<?>> properties) {<br>
                    for (Property<?> element : properties) {<br>
                        <span style="background-color:rgb(255,255,0)"><T>
              Property<T> property = element;</span><br>
                        T value = property.value();<br>
                        assert property.has(value);  // no cast needed
            here!<br>
                    }<br>
                }<br>
          </span><br>
        </div>
        <div>but here's what we HAVE to do today to avoid the unchecked
          cast:</div>
        <div><br>
        </div>
        <div><span style="font-family:monospace">    public void
            verifyHas(List<Property<?>> properties) {<br>
                    for (Property<?> property : properties) {<br>
                        verifyHas(property);<br>
                    }   <br>
                }       <br>
                    <br>
                // Ugh. This method exists solely to declare <T>
            so we can avoid an unchecked cast<br>
                private <T> void verifyHas(Property<T>
            property) {<br>
                    T value = property.value();<br>
                    assert property.has(value);<br>
                }</span></div>
        <div><br>
        </div>
        <div>If we're going to add "Pattern Assignment" it seems like it
          would be reasonable for generic type variables to also
          benefit.</div>
        <div><br>
        </div>
        <div>Cheers,</div>
        <div>-Archie</div>
        <div><br>
        </div>
        <div><span class="gmail_signature_prefix">-- </span></div>
        <div dir="ltr" class="gmail_signature">Archie L. Cobbs<br>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>