I'm studying switch expressions and I think I found a weird behaviour:
public static boolean isTimeToParty(Day day) {
switch (day) {
case MONDAY -> dog(); //expression allowed
case TUESDAY -> 2 + 2; //error: not a statement
case WEDNESDAY -> true; //error: not a statement
default -> System.out.println("");
}
return false;
}
public static int dog() {
return 2;
}
Why can I type as value dog()
which is an expression but other types of expression are not allowed? Intellij prompts me with "not a statement"
error.
Thanks in advance.