RFR: JDK-8240998: Implement javac changes for deconstruction patterns.

Remi Forax forax at univ-mlv.fr
Wed Mar 18 09:57:19 UTC 2020


Hi Jan,
in the CSR part,
you don't talk about the drawbacks of using a deconstruction pattern, the syntax of a deconstruction pattern forces you to declare the number of record components you have, so adding (by example) one record component to a record will makes the code of instanceof to not compile anymore.

Let say you have
  record Point(int x, int y);
with the current instanceof one can write
  if (o instanceof Point p) {
    System.out.println(p.x() + " " + p.y());
  }
with a deconstruction pattern, you will write
  if (o instanceof Point(int x, int y)) {
    System.out.println(x + " " + y);
  }

now if you change Point to
  record Point(int x, int y, int z);
the first code still compile but the second doesn't not anymore (but it still works at runtime in case of separate compilation).

It's not a big deal, it doesn't make the deconstruction pattern useless at all but I think it's something developers should be aware of.

regards,
Rémi

----- Mail original -----
> De: "jan lahoda" <jan.lahoda at oracle.com>
> À: "compiler-dev" <compiler-dev at openjdk.java.net>
> Cc: "amber-dev" <amber-dev at openjdk.java.net>
> Envoyé: Mercredi 18 Mars 2020 09:55:11
> Objet: RFR: JDK-8240998: Implement javac changes for deconstruction patterns.

> Hi,
> 
> I would like to ask for a review for a patch that implements the
> deconstruction patterns, as described in JEP 375:
> https://bugs.openjdk.java.net/browse/JDK-8235186
> 
> The current specification draft is here:
> http://cr.openjdk.java.net/~gbierman/jep375/jep375-20200316/specs/patterns-instanceof-jls.html
> 
> For this phase, the proposal is for javac to desugar the deconstruction
> patterns using record accessors.
> 
> The CSR for this change is being written here:
> https://bugs.openjdk.java.net/browse/JDK-8240999
> 
> The proposed patch:
> http://cr.openjdk.java.net/~jlahoda/8240998/webrev.00
> 
> JBS: https://bugs.openjdk.java.net/browse/JDK-8240998
> 
> Any feedback is welcome!
> 
> Thanks,
>      Jan


More information about the compiler-dev mailing list