val lotto = listOf(1,2,3,4,5,6).map(::LottoNumber)
private fun List<LottoNumber>.match2(winningLotto: List<LottoNumber>): Int{
return return count{ winningLotto.contains(it) }
}
//
val matchCount = userLotto.match2(winningLotto)
//
//이걸 Lotto 클래스로 옮김
fun match(winningLotto: Lotto) :Int{
return this.number.contains(it)
}
winningLotto.match(userLotto)
fun Lotto(vararg number: Int): Lotto{
return Lotto(numbers.map(::LottoNumber))
}
이렇게 가변인자를 사용해 로또를 만들어주는 함수를 만들면 좀더 간편하게 적기 가능
constructor(vararg numbers: Int): this(numbers.map(::LottoNumber))
@Disabled
= 테스트 무시하는 코드
class LottoNumbers(numbers: List<Int>){
private val _numbers: MutableList<Int> = numbers.toMutableList()
val numbers: List<Int>
get() = _numbers.toList) //커스텀게터
fun add(number: Int){
_numbers = add(number)
}
fun clear(){
_numbers = clesr()
}
}
새로운 리스트 변수를 선언하고 거기에 넣는다
toList()도 해주기
값이 변경되는 것은
val VS var 의 문제 X / List VS MutableList 의 문제
백킹프로퍼티 = 뒷받침해주는 프로퍼티(_numbers)
여기서 어떻게 numbers를 뚫 것인가????
actual.numbers as MutableList<Int>.add(7)