Two new draft pattern matching JEPs

Tagir Valeev amaembo at gmail.com
Fri Feb 19 04:47:27 UTC 2021


Ah, indeed, thanks! Sorry for the noise then.


On Thu, Feb 18, 2021 at 10:25 PM Brian Goetz <brian.goetz at oracle.com> wrote:
>
>
> On 2/18/2021 7:52 AM, Tagir Valeev wrote:
> > Hello!
> >
> > Thank you!
> >
> > There's a sample in Nested Record and Array Patterns draft:
> >
> > static void printColorOfUpperLeftPoint(Object o) {
> >      if (o instanceof Rectangle(ColoredPoint ul, ColoredPoint lr)){
> >          if (ul instanceof ColoredPoint(Point p, Color c)) {
> >              System.out.println(c);
> >          }
> >      }
> > }
> >
> > It looks like here, the nested pattern "ul instanceof
> > ColoredPoint(Point p, Color c)" is total. I thought that there's idea
> > to prohibit total patterns with instanceof (at least total type test
> > patterns are already prohibited). Please correct me if I'm wrong.
> >
>
> Slightly wrong :)
>
> We prohibit total _type_ patterns in instanceof.  (Alternately, we could
> phrase it: we prohibit total patterns with empty remainder.) But a total
> record pattern is OK, because it has remainder { null }.
>
> Recall the motivation: avoid confusion with `o instanceof Object`. Only
> the patterns where such a confusion could occur need to be restricted.


More information about the amber-spec-experts mailing list