JEP 405 update
Remi Forax
forax at univ-mlv.fr
Wed Feb 9 16:40:08 UTC 2022
Hi Gavin,
I don't buy the argument that record patterns promote a null-safe style of programming as this is stated several times in the JEP.
The ""null-safety"" (notice the air quotes) mostly comes from the instanceof or the switch (which semantics is equivalent of a cascade of if instanceof), not from the record pattern by itself.
You can argue that when a record pattern is nested a nullcheck appears, but it's more than the underlying semantics is a degenerated instanceof when the declared type and the instanceof type are the same.
The record pattern is about destructuring after the instanceof/nullcheck has been done, so i find that argument counter productive because it does not help to understand the semantics.
Also, we have talked several times to introduce the record pattern when doing an assignment
Point point = ...
Point(int x, int y) = point;
// can use x and y here !
This will throw a NPE if point is null, similarly to an unboxing operation.
The null-safety is not attached to the record pattern per se but by the container that use it (instanceof, case of a switch, enclosing pattern).
regards,
Rémi
----- Original Message -----
> From: "Gavin Bierman" <gavin.bierman at oracle.com>
> To: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> Sent: Wednesday, February 9, 2022 12:59:02 PM
> Subject: JEP 405 update
> Dear experts,
>
> Just to let you know that I have updated JEP 405:
>
> https://openjdk.java.net/jeps/405
>
> You will see that we have removed the array patterns from this JEP (and it has
> been retitled accordingly). We're still committed to supporting a direct pattern
> form for arrays, but given our tight schedule and a number of queries about the
> exact syntactic form for array patterns, we think we'll be better off decoupling
> them from JEP 405, and releasing them in a future patterns JEP.
>
> Comments welcomed!
> Gavin
More information about the amber-spec-experts
mailing list