[Kotlin] Enum 값으로 객체 Enum 객체 찾기
enum class Number(var code: Int, var ordinalNumber:String){ One(1,"First"), Two(2,"Second"), Three(3,"Third"), Four(4,"Fourth"), Five(5,"Fifth"), } fun fromCode(code: Int): Number { return Arrays.stream(Number.values()) .filter { v -> v.code == code } .findAny() .orElseThrow { IllegalArgumentException(String.format("%s이 존재하지 않습니다.", code)) } } 출력 println(fromCode(3).name) println(fromCode(3).ord..
2022. 10. 12.