[External] : Re: Fwd: Two new draft pattern matching JEPs

John Rose john.r.rose at oracle.com
Tue Mar 9 20:37:48 UTC 2021


On Mar 9, 2021, at 12:23 PM, John Rose <john.r.rose at oracle.com> wrote:
> 
> If switch refactors
> to an if-chain, why then continue-switch would refactor to
> continue-if, which turns out to branch to the next “else”,
> if any.

A bit more detail in case that was cryptic:

switch (obj) {
...
case P &&guard G: …
…
}

<=refactor=>

switch (obj) {
...
case P: { if (!G) continue switch; } ...
…
}

<=refactor=>

val $it = obj;
if ...
else if ($it instanceof P && G) { ...
} else …

<=refactor=>

val $it = obj;
if ...
else if ($it instanceof P) {
  { if (!G) continue if; } ...
} else …

(No sub-cases here, BTW.)

The enhanced continue statement allows guards
to be refactored to interact with ad hoc variable
bindings and/or control flow as:

switch (obj) {
...
case P:
  if (Q) return quickwin();
  var X = …; if (!G(X)) continue switch;
  ...
…
}

Still, the above does not yet seem to constitute
any killer use cases.

Also, frankly, “continue if” is probably liable to
bad abuses.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20210309/7bfa334b/attachment.htm>


More information about the amber-spec-experts mailing list