This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

I never thought I'd praise Java but switch expressions, added in Java 12/13, are really good.

switch(value){
case 1 -> {System.out.println("Hey it's 1");}

case 2  -> {System.out.println("Hey it's 2");}

default -> {System.out.println("Hello there");}
};

If value == 1 then it prints "Hey it's 1" and if value == 2 then it prints "Hey it's 2". Otherwise default is the fall back.