febs
12/10/2018, 7:34 AMWith 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 🙏
karelpeeters
12/10/2018, 9:08 AMconst 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.karelpeeters
12/10/2018, 9:08 AMAndreas Sinz
12/10/2018, 9:08 AMval
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)febs
12/10/2018, 10:43 AM