From Enum To Set with EnumSet #java #shorts #coding #airhacks

preview_player
Показать описание

Java used in this short: openjdk version "21" 2023-09-19 LTS

#airhacks
Рекомендации по теме
Комментарии
Автор

EnumMap / Set are nice

private enum Choice {
SCISSORS, ROCK, PAPER, LIZARD, SPOCK
}
private static final EnumMap<Choice, Set<Choice>> WIN_CONDITIONS = new EnumMap<>(Map.of(
Choice.SCISSORS, EnumSet.of(Choice.PAPER, Choice.LIZARD),
Choice.ROCK, EnumSet.of(Choice.SCISSORS, Choice.LIZARD),
Choice.PAPER, EnumSet.of(Choice.ROCK, Choice.SPOCK),
Choice.LIZARD, EnumSet.of(Choice.SPOCK, Choice.PAPER),
Choice.SPOCK, EnumSet.of(Choice.SCISSORS, Choice.ROCK)
));

:D

marmont