About underscores in type arguments / partial type arguments
Remi Forax
forax at univ-mlv.fr
Sat Jan 21 07:00:54 UTC 2023
> From: "Tesla Ice Zhang" <ice1000kotlin at foxmail.com>
> To: "amber-dev" <amber-dev at openjdk.org>
> Sent: Saturday, January 21, 2023 3:23:39 AM
> Subject: About underscores in type arguments / partial type arguments
> Hi all,
> 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
> The demonstration of the feature in the above document is also applicable to
> Java.
Yes, this has been discussed several times not only in the context of patterns but also in the context of inference in general.
For patterns, currently you have to repeat all type arguments
Map<String, Integer> map = ...
switch(map) {
case HashMap<String, Integer> m -> ...
...
we talk about simplify it using
case HashMap<> m -> ...
but this means also supporting
if (map instanceof HashMap<> m) { ...
and maybe also supporting
if (map instanceof HashMap) {
var m = (HashMap<>) map;
...
}
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.
Currently, we are trying to see if we can avoid to specify the angle brackets all together, so more "case HashMap" than "case HashMap<>".
see https://cr.openjdk.java.net/~gbierman/jep432%2b433/jep432+433-20221115/specs/patterns-switch-record-patterns-jls.html#jls-18.5.5
> Best regards,
> Tesla
regards,
Rémi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20230121/a9d371bb/attachment.htm>
More information about the amber-dev
mailing list