Patterns and nulls
Stephen Colebourne
scolebourne at joda.org
Wed Mar 14 21:35:08 UTC 2018
On 14 March 2018 at 16:58, Brian Goetz <brian.goetz at oracle.com> wrote:
> Let's assume we have the following declarations:
>
> record Box(Object);
> Object o;
> String s;
> Box b;
>
> Implicitly, `Box` has a deconstruction pattern whose signature is `Box(out
> Object o)`.
>
> What will users expect on the following?
>
> Box b = new Box(null);
> switch (b) {
> case Box(Candy x): ...
> case Box(Frog f): ...
> case Box(Object o): ...
> }
>
> There are four non-ridiculous possibilities:
> - NPE
> - Match none
> - Match Box(Candy)
> - Match Box(Object)
If records were changed to not allow null, then `new Box(null)` would
not be possible. Would that not change the line of reasoning here?
Stephen
More information about the amber-dev
mailing list