<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>"Tesla Ice Zhang" <ice1000kotlin@foxmail.com><br><b>To: </b>"amber-dev" <amber-dev@openjdk.org><br><b>Sent: </b>Saturday, January 21, 2023 3:23:39 AM<br><b>Subject: </b>About underscores in type arguments / partial type arguments<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;">Hi all,<br><div>Is there any discussion related to partially specified type arguments (which are left for inference)? I just saw that Kotlin 1.7 added support for that. It would be nice if Java can have that too: https://kotlinlang.org/docs/whatsnew17.html#underscore-operator-for-type-arguments</div><br><div>The demonstration of the feature in the above document is also applicable to Java.</div></blockquote><div><br></div><div>Yes, this has been discussed several times not only in the context of patterns but also in the context of inference in general.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>For patterns, currently you have to repeat all type arguments<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>  Map<String, Integer> map = ...<br data-mce-bogus="1"></div><div>  switch(map) {<br data-mce-bogus="1"></div><div>    case HashMap<String, Integer> m -> ...<br data-mce-bogus="1"></div><div>    ...<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>we talk about simplify it using<br data-mce-bogus="1"></div><div>   case HashMap<> m -> ...<br data-mce-bogus="1"></div><div>  <br data-mce-bogus="1"></div><div>but this means also supporting</div><div>  if (map instanceof HashMap<> m) { ...<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>and maybe also supporting<br data-mce-bogus="1"></div><div>  if (map instanceof HashMap) {<br data-mce-bogus="1"></div><div>    var m = (HashMap<>) map;<br data-mce-bogus="1"></div><div>    ...<br data-mce-bogus="1"></div><div>  }<br data-mce-bogus="1"></div><div>  <br data-mce-bogus="1"></div><div>One issue is that the inference rules are not the same as the usual inference rules, because you want to be able to infer something like HashMap<?,?> while you do not want to infer new HashMap<?,?>() in the general context.</div><div><br data-mce-bogus="1"></div><div>Currently, we are trying to see if we can avoid to specify the angle brackets all together, so more "case HashMap" than "case HashMap<>".<br></div><div>see https://cr.openjdk.java.net/~gbierman/jep432%2b433/jep432+433-20221115/specs/patterns-switch-record-patterns-jls.html#jls-18.5.5<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;"><br><div>Best regards,</div><div>Tesla</div></blockquote><div><br></div><div>regards,<br data-mce-bogus="1"></div><div>RĂ©mi<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div></div></div></body></html>