the new switch (with -> ) allows for many changes besides the symbol
- return a value (can be void as the usual one)
double d = switch(o) {…}
- allows variable declaration with pattern matching
case int i -> i+1
- guarding
case float f when f>0 ->…
- provides
yield for block case char c-> {countChar++;yield count;}
- null case allowed
case null -> …
- deconstruction of records
case Segment(Point2D(int x1, int y1), Point2D(int x2, int y2))-> …
https://docs.oracle.com/en/java/javase/25/language/pattern-matching-switch.html
the new switch (with
->) allows for many changes besides the symboldouble d = switch(o) {…}case int i -> i+1case float f when f>0 ->…yieldfor blockcase char c-> {countChar++;yield count;}case null -> …case Segment(Point2D(int x1, int y1), Point2D(int x2, int y2))-> …https://docs.oracle.com/en/java/javase/25/language/pattern-matching-switch.html