[모각글] 2023-11-07 #3
cheese10yun
started this conversation in
General
Replies: 3 comments
-
Spring Data MongoDB Repository 확장
|
Beta Was this translation helpful? Give feedback.
0 replies
-
프로젝트 설계
|
Beta Was this translation helpful? Give feedback.
0 replies
-
코틀린 인 액션과 코틀린을 활용한 로또 뽑기 구현회사에서 사용하고 있는 언어라 코틀린 인 액션을 활용해 언어를 학습하고 있습니다. 읽다가 생각한 내용들을 정리했습니다.
코틀린으로 로또 계산기 만들고 있는데 이번에 학습한
AS-IS enum class TicketType {
Manual,
Auto,
}
data class LottoGame(
val numbers: LottoNumbers,
val type: TicketType,
) TO-BE sealed class LottoGame(val numbers: LottoNumbers) {
class Manual(manualNumbers: LottoNumbers) : LottoGame(manualNumbers)
class Auto(autoNumbers: LottoNumbers) : LottoGame(autoNumbers)
} 수동과 자동을 몇 장 뽑았는지 어떤 번호를 출력 했는지를 출력하는 메서드도 있는데 코틀린에서 제공하는 확장 함수도 활용 할 수 있었습니다. AS-IS val manualGames = lottoGames.filter { it.type == TicketType.Manual }
val autoGames = lottoGames.filter { it.type == TicketType.Auto } TO-BE val manualGames = lottoGames.filterIsInstance<LottoGame.Manual>()
val autoGames = lottoGames.filterIsInstance<LottoGame.Auto>() |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
[모각글] 2023-11-07
현재 작성 중인 글과 관련된 관심사, 그리고 회사에서의 고민에 대해 자유롭게 이야기해보겠습니다.
Beta Was this translation helpful? Give feedback.
All reactions