var _ vs _
Cay Horstmann
cay.horstmann at gmail.com
Fri May 26 10:32:59 UTC 2023
With JDK build 24, the following works:
record Point(int x, int y) {}
...
Point p = ...;
String description = switch (p) {
case Point(var x, var _) when x == 0 -> "on y-axis";
case Point(_, var y) when y == 0 -> "on x-axis";
case Point(var _, var _) -> "something else";
};
But this switch is not deemed exhaustive:
String description = switch (p) {
case Point(var x, var _) when x == 0 -> "on y-axis";
case Point(_, var y) when y == 0 -> "on x-axis";
case Point(_, _) -> "something else";
};
Is that a bug, or is there some subtle difference between var _ and _?
Thanks,
Cay
--
--
Cay S. Horstmann | http://horstmann.com | mailto:cay at horstmann.com
More information about the amber-spec-observers
mailing list