Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- 코드포스
- Kotlin
- Python
- GitHub
- activity
- 암호학
- TEST
- Hilt
- relay
- pandas
- textfield
- android
- androidStudio
- livedata
- Rxjava
- 코루틴
- AWS
- Compose
- 백준
- boj
- MyVoca
- 프로그래머스
- architecture
- MiTweet
- Coroutines
- ProGuard
- Gradle
- Codeforces
- 쿠링
- Coroutine
Archives
- Today
- Total
목록enum (1)
이동식 저장소
[Kotlin] sealed class vs. enum class
Kotlin을 처음 배울 때는 ``enum class``와 ``sealed class``를 혼동하곤 했다. enum을 구현할 떄 ``enum class`` 대신 ``sealed class``를 써도 되지 않나? 결론 ``sealed class``를 써도 되지만, 바람직한 사용법은 아니다. 왜? ``enum class``가 왜 적합한지는 설명 안 해도 되겠지? 이제 ``sealed class``의 바람직한 사용 예시를 설명하려 한다. ``sealed class``는 클래스가 정의된 블럭 안에서만 상속될 수 있으며, 외부에서의 상속을 허용하지 않는다. sealed class Animal { // Animal은 이 안에서만 상속될 수 있다. class Cat: Animal class Dog: Animal } ..
Primary/Kotlin
2022. 7. 7. 14:14