Pattern Matching - why "when" instead of "if"?

Lou ? l.spitzmueller at hotmail.de
Tue Dec 12 01:26:30 UTC 2023


Hello there,

I'm new to the jdk mailing list and hope this is the right place to ask. If this is the wrong place to ask, please let me know.
I work with Java over 10 years and searched through all subjects in the project loom mailing list for the term "when" but couldn't find an answer to my question:

Why did a new keyword ("when") got introduced for guarded patterns instead of simply reusing "if"?

Since its an arbitrary (non-exhaustive) check/condition, "when" seems to be equivalent to "if", except that round brackets are not required.
Would it be conceivable (in the interests of consistency) to stay with (or also allow) "if" instead of "when"?
If not I'd be very much interested in the reasoning to get a better grasp about "when" and the differentiation from "if".

Thank you very much for your time and care for thought through quality. A core reason for my love to Java.

Best regards
Lorenz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20231212/c6cada1d/attachment.htm>


More information about the loom-dev mailing list