Why can't I have a `get() = { return 7 }`
# getting-started
r
Why can't I have a
get() = { return 7 }
s
You probably want
get() = 7
or
get() { return 7 }
. Unless you're actually trying to return a
() -> Int
function.
r
@Sam I need the get to run a for loop and then return the result
val x get() = { let sum = 0; for ... do sum += whatever; return sum }
s
It should work if you just get rid of the
=
at the start. You might also need an explicit type, so
val x: Int get() { … }
. Do you still see an error after that?
r
oh okay, thanks