> From: "Brian Goetz" <brian.go...@oracle.com> > To: "Remi Forax" <fo...@univ-mlv.fr> > Cc: "amber-spec-experts" <amber-spec-experts@openjdk.java.net> > Sent: Wednesday, January 26, 2022 1:23:04 PM > Subject: Re: [External] : Re: Diamond in type patterns (was: Reviewing > feedback > on patterns in switch)
>> The questions we did not answer the last time we talk about that subject >> - why should we allow raw types here ? > We already have a clear precedent with type patterns in instanceof — which is > not a preview feature any more. So for one, now you’re talking about making a > *change* to the existing language semantics. There are other concerns too. >> - given that this is equivalent to an instanceof + cast, why we can not use >> diamond inference on cast ? > You’re not being clear about what you’re saying, you could be saying either of > the following (or others): > - You’re proposing diamond here, but not there, then your proposal is > inconsistent, and therefore stupid. > - I love your proposal, but I think we should additionally talk about other > places to use diamond as well. > I can’t tell which of these you’re saying, or maybe its something else? I think we should figure out how it should work on cast and then we can happily applied it on patterns. >> - how this inference work ? Is is the same inference than with the diamond >> constructor ? > Again, I can’t tell whether you’re saying “this is dumb, it can’t work”, or > “this is great, but I can’t figure out the details.” The rules for what you can use as argument of a type parameter when doing a new and when doing a cast are not the same, for examples, new ArrayList<?>() is not a valid code while (ArrayList<?>) is a perfect valid cast, new ArrayList<String>[3] is not a valid code while (ArrayList<String>[]) may or may not be a valid cast, new ArrayList<Object>() is a valid code while (ArrayList<Object>) may or may not be a valid cast . despite the syntax being the same, the diamond syntax, i don't think we can reuse the same inference rules between the new diamond and the cast diamond. regards, Rémi