https://kotlinlang.org logo
#kotlin-native
Title
# kotlin-native
m

My Nguyen

12/14/2021, 9:26 AM
Just for fun. Let's guess the output result.
Copy code
data class MyNumber(
    var x: Int
) {
    val isBig1: Boolean = x >= 10

    val isBig2: Boolean
        get() = x >= 10
}

fun main() {
    val number = MyNumber(9)
    println("isBig1 before: ${number.isBig1}")
    println("isBig2 before: ${number.isBig2}")
    number.x = 11
    println("isBig1 after: ${number.isBig1}")
    println("isBig2 after: ${number.isBig2}")
}
👀 1
r

rudolf.hladik

12/14/2021, 10:29 AM
Copy code
false
false
false
true
that’s because isBig2 is actually getter
2
3 Views