<div dir="auto">I'm not sure how well this would fit in Java, but rust has long reaching backwards inference. Example:<div dir="auto">var hashmap = new Hashmap<>();</div><div dir="auto">hashmap.add(5, "Hello");</div><div dir="auto">Where the first use of a type variable here int, String infers the type of the hashmap.</div><div dir="auto">This would allow patterns to avoid specifying the type variables they want by inferring them by usage inside the pattern.</div><div dir="auto"><br></div><div dir="auto">Great regards </div><div dir="auto">RedIODev </div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jan 21, 2023, 08:01 Remi Forax <<a href="mailto:forax@univ-mlv.fr">forax@univ-mlv.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:arial,helvetica,sans-serif;font-size:12pt;color:#000000"><div><br></div><div><br></div><hr id="m_-6008077281224607691zwchr"><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"><b>From: </b>"Tesla Ice Zhang" <<a href="mailto:ice1000kotlin@foxmail.com" target="_blank" rel="noreferrer">ice1000kotlin@foxmail.com</a>><br><b>To: </b>"amber-dev" <<a href="mailto:amber-dev@openjdk.org" target="_blank" rel="noreferrer">amber-dev@openjdk.org</a>><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><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: <a href="https://kotlinlang.org/docs/whatsnew17.html#underscore-operator-for-type-arguments" target="_blank" rel="noreferrer">https://kotlinlang.org/docs/whatsnew17.html#underscore-operator-for-type-arguments</a></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></div><div><br></div><div>For patterns, currently you have to repeat all type arguments<br></div><div><br></div><div>  Map<String, Integer> map = ...<br></div><div>  switch(map) {<br></div><div>    case HashMap<String, Integer> m -> ...<br></div><div>    ...<br></div><div><br></div><div>we talk about simplify it using<br></div><div>   case HashMap<> m -> ...<br></div><div>  <br></div><div>but this means also supporting</div><div>  if (map instanceof HashMap<> m) { ...<br></div><div><br></div><div>and maybe also supporting<br></div><div>  if (map instanceof HashMap) {<br></div><div>    var m = (HashMap<>) map;<br></div><div>    ...<br></div><div>  }<br></div><div>  <br></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></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 <a href="https://cr.openjdk.java.net/~gbierman/jep432%2b433/jep432+433-20221115/specs/patterns-switch-record-patterns-jls.html#jls-18.5.5" target="_blank" rel="noreferrer">https://cr.openjdk.java.net/~gbierman/jep432%2b433/jep432+433-20221115/specs/patterns-switch-record-patterns-jls.html#jls-18.5.5</a><br></div><div><br></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></div><div>Rémi<br></div><div><br></div></div></div></div></blockquote></div>