There's a third cool thing that JEP 406 (openjdk.java.net/jeps/406) brings to #Java17: guarded patterns! But... isn't this just like common &&? Why reinvent that wheel? Because it makes patterns more expressive and coding with them more flexible. Here's how! 1/7
3
29
108
0
13
Download Image
First, the basics: A guarded pattern has the form `$PATTERN && $BOOLEAN_EXPR`. If (and only if) $PATTERN evaluates to true, the respective variables are introduced and $BOOLEAN_EXPR is evaluated. If it's also true, the entire guarded pattern is true. 2/7
@nipafx Hm. I'm not sure if I like guarded patterns. To me readability is key, and even though I understand it pulls things together, it also confuses what were simple boolean expressions. #notconvinced #yet