dl (1) 썸네일형 리스트형 [Kotlin] switch to when with enum 자바의 switch는 when으로 변경할 수 있다. 자바의 switch는 문(statement)이지만 코틀린의 when은 식(expression)이다. 코들린의 When을 쓰면서 좋은 점은 enum에 대한 분기를 할 때 default를 넣지 않아도 된다는 것이다. 예를들어 아래와 같은 2대 통신사의 열거형이 있다고 하면, public enum Telecom { SKT, KT, } 어떤 처리기를 만들어주는 팩토리를 구현을 할 때 아래와 같이 만든다면 switch 끝의 라인에 에러를 만난다. interface TelecomHandler { void handle(); } class TelecomFactory { public TelecomHandler create(Telecom telecom) { switch .. 이전 1 다음