Before JDK 12, a switch statement allowed a single label per case. Starting with the switch expressions, a case can have multiple labels separated by a comma. Check out the following method that exemplifies multiple case labels:
private static SportType
fetchSportTypeByPlayerType(PlayerTypes playerType) {
return switch (playerType) {
case TENNIS, GOLF, SNOOKER ->
new Individual();
case FOOTBALL, VOLLEY ->
new Team();
};
}
So, if we pass to this method TENNIS, GOLF, or SNOOKER, it will return an instance of the Individual class. If we pass FOOTBALL or VOLLEY, it will return an instance of the Team class.