switch Advanced Usage

 public enum PlayerTypes {
        TENNIS,
        FOOTBALL,
        BASKETBALL,
        PINGPANG,
        UNKNOWN
    }
private static String createPlayer(PlayerTypes playerType) {
    return switch (playerType) {
        case TENNIS -> "网球运动员";
        case FOOTBALL -> "足球运动员";
        case BASKETBALL,PINGPANG -> "牛逼运动员沉默王二";
        case UNKNOWN -> throw new IllegalArgumentException("未知");
    };
}
Published 57 original articles · won praise 0 · Views 4540

Guess you like

Origin blog.csdn.net/Arry_Coding/article/details/104632875