Consider following Kotlin-Code:
class Foo(input: Int) {
private var someField: Int = input
get() = -field
set(value) {
field = -value
}
fun bar() {
println(someField)
}
}
fun main() {
Foo(1).bar()
}
This prints -1
in the console which means that inside method bar()
someField
references the attribute and not the corresponding getter. Is there a way that allows me to use the get()
-method as if I was referencing this field from outside?