I feel like this sentence from an article I'm read...
# getting-started
f
I feel like this sentence from an article I'm reading is incorrect:
With Java, in-memory data “storage” comes in four shapes: variables, parameters, fields, and constants, in order of scope.
With Kotlin, parameters are similar with a few variations. They are final (so they cannot be assigned a new value), can have a default value (so we can omit > them when calling it) and their names matter (as we can use them when invoking).
Now, for the other three, things are more different. As in, they are all defined as properties.
I understood that properties are related to objects/classes (and they might have a backing field), but if I declare a val or var in a function then that is a variable Am I correct? Or wrong? Thank you 🙏
k
Depends really.
Copy code
const val x = 4
class A(val y: Int) {
    fun foo(z: Int) {
        val w = 7
    }
}
That's 3 different things val can mean: part of a constant, class property and variable.
I wouldn't get too hung up on terminology though.
a
A local
val
or
var
is used just like a variable, but it actually is a local property (you can even use delegates there https://kotlinlang.org/docs/reference/delegated-properties.html#local-delegated-properties-since-11)
👍 1
f
But I can't define a getter though.