class PhoneBookIncorrect {
// ...
// 나쁜 습관
fun String.isPhoneNumber() = length == 7 && all { it.isDigit() }
}
PhoneBookIncorrect().apply { "1234567890".test() } // 이렇게 사용해야 함
class PhoneBookIncorrect {
// ...
}
private fun String.isPhoneNumber() = length == 7 && all { it.isDigit() }
val ref = String::isPhoneNumber
var str = "1234567890"
val boundedRef = str::isPhoneNumber
val refX = PhoneBookIncorrect::isPhoneNumber // 오류
val book = PhoneBookIncorrect()
val boundedRefX = book::isPhoneNumber // 오류
class A {
val a = 10
}
class B {
val a = 20
val b = 30
fun A.test() = a + b // 40? 50?
}
class A {
// ...
}
class B {
// ...
fun A.update() { /*...*/ } // A와 B 중 어떤 것을 업데이트할까?
}