int val = switch (str) {
case "foo" -> 1;
case "bar" -> 2;
case "baz" -> 3;
default -> -1;
}
Looks a lot like Scala: val foo = match (str) {
case "foo" => 1
case "bar" => 2
case "baz" => 3
case _ => -1
}
Interestingly the underscore character is now reserved in Java, wonder what use case(s) they have in mind there?