> De: "Guy Steele" <guy.ste...@oracle.com> > À: "Alan Malloy" <amal...@google.com> > Cc: "Remi Forax" <fo...@univ-mlv.fr>, "amber-spec-experts" > <amber-spec-experts@openjdk.java.net> > Envoyé: Lundi 7 Septembre 2020 17:51:06 > Objet: Re: Is case var(var x, var y) a valid syntax ?
> I agree with Alan. While I believe that Rémi is correct insofar as you can > write > “var” in place of a type in any type pattern “T x”, in a deconstruction > pattern > “P(...) [d]” the occurrence of P is not a type; rather, it names a > deconstructor. It does so happen that right now all deconstructors (like all > constructors) share the name of an associated type, but it is important not to > confuse them. You cannot replace a deconstructor name with “var” any more than > you can write “new var()” or “new MyInterface()”. hum, technically you can write new MyInterface() { ... } I disagree with that rational because a deconstructor is an instance method, so you need to do an instanceof first, said differently P(...) is a deconstruction pattern which is equivalent to instanceof P p && var values = p.__name_of_the_deconstructor() > From Brian, > There are about a zillion places where you can use types and can’t use var: > array elements, import statement, type parameters, etc. this is just one of > those. There is a good reason to not use var for all of them, i believe. > —Guy Rémi >> On Sep 7, 2020, at 5:36 AM, Alan Malloy <amal...@google.com> wrote: >> I would be very surprised if that were valid. The inner vars are fine, of >> course. However, your outer one has not replaced a type, but a deconstructor >> reference, or whatever we're calling the opposite of a constructor. "Any >> object >> which can be deconstructed into two constituent objects" will surely not be a >> useful query very often, and I wouldn't expect the language to support it. >> On Mon, Sep 7, 2020, 1:24 AM Remi Forax < [ mailto:fo...@univ-mlv.fr | >> fo...@univ-mlv.fr ] > wrote: >>> Just a question, >>> do we agree that the syntax below is valid ? >>> Point point = ... >>> switch(point) { >>> case var(var x, var y): ... >>> } >>> i.e. that var can be written everywhere there is a type in a Pattern. >>> Rémi