Gasan
10/31/2025, 10:44 AMval? Kotlin does not have a concept of a "pointer to a const", therefore I can change the referenced value, unless it is immutable. I mean, val parameter variable does not amount to much unless the referenced value is immutable.Vampire
10/31/2025, 10:54 AMvar nor val, if you try to use it, you get ... on function parameter is prohibitedGasan
10/31/2025, 10:55 AMval and Kotlin does not allow to make them var.Vampire
10/31/2025, 10:56 AMGasan
10/31/2025, 10:57 AMVampire
10/31/2025, 10:57 AMGasan
10/31/2025, 10:57 AMGasan
10/31/2025, 10:57 AMVampire
10/31/2025, 10:58 AMVampire
10/31/2025, 10:58 AMGasan
10/31/2025, 10:59 AMVampire
10/31/2025, 10:59 AMVampire
10/31/2025, 10:59 AMVampire
10/31/2025, 10:59 AMGasan
10/31/2025, 11:00 AMVampire
10/31/2025, 11:00 AMGasan
10/31/2025, 11:00 AMGasan
10/31/2025, 11:01 AMVampire
10/31/2025, 11:01 AMGasan
10/31/2025, 11:02 AMVampire
10/31/2025, 11:02 AMGasan
10/31/2025, 11:02 AMVampire
10/31/2025, 11:03 AMThat was to your comment "it's totally different"Doesn't really rely to that. Even with that statement it doesn't change that it is something completely different. π
Vampire
10/31/2025, 11:03 AMGasan
10/31/2025, 11:05 AMVampire
10/31/2025, 11:06 AMVampire
10/31/2025, 11:06 AMVampire
10/31/2025, 11:06 AMVampire
10/31/2025, 11:06 AMGasan
10/31/2025, 11:06 AMVampire
10/31/2025, 11:07 AMVampire
10/31/2025, 11:07 AMval-thing in Kotlin is immutableVampire
10/31/2025, 11:07 AMGasan
10/31/2025, 11:07 AMval then?Vampire
10/31/2025, 11:08 AMGasan
10/31/2025, 11:08 AMVampire
10/31/2025, 11:09 AMVampire
10/31/2025, 11:09 AMok, I cannot assign a different value, but I can modify the value. Which is effectively the same thing.No, that's a completely different thing
Gasan
10/31/2025, 11:09 AMVampire
10/31/2025, 11:09 AMVampire
10/31/2025, 11:10 AMWhat are the situations in which it would make a difference?They are just completely different things to do
Vampire
10/31/2025, 11:10 AMVampire
10/31/2025, 11:11 AMval would make sense nowhere, also not on fields / properties.Vampire
10/31/2025, 11:11 AMGasan
10/31/2025, 11:15 AMval parameter to me seems like a guarantee that if you modify it, you modify the same object. val parameter does not mean that you won't modify the parameter value.Sam
10/31/2025, 11:15 AMSam
10/31/2025, 11:16 AMVampire
10/31/2025, 11:17 AMSam
10/31/2025, 11:18 AMVampire
10/31/2025, 11:19 AMSam
10/31/2025, 11:22 AMthanksforallthefish
10/31/2025, 12:34 PMok, I cannot assign a different value, but I can modify the value. Which is effectively the same thing.I think the point is this assumption, to me this is like saying that I can enter my home by opening the door or by smashing it, I achieve the same result, at least for an external observer (I am now inside), but I would hardly call it "the same thing"
Gasan
10/31/2025, 12:35 PMKlitos Kyriacou
10/31/2025, 12:47 PMGasan
10/31/2025, 12:48 PMGasan
10/31/2025, 12:49 PMHuib Donkers
10/31/2025, 1:14 PMclass A {
private var _foo = 0
val foo: Int get() = _foo++
}
fun bar(immutable a: A) {
a.foo // error?
}
[2]
interface I {
val x: Int
fun foo()
}
class A: I {
override var x = 0
private set
override fun foo() {}
}
class B: I {
override var x = 0
private set
override fun foo() { x++ }
}
fun bar(immutable i: I) {
i.foo() // error?
}Gasan
10/31/2025, 4:07 PMGasan
10/31/2025, 4:09 PMKlitos Kyriacou
10/31/2025, 4:58 PMclassify each method of the type, whether it's mutating or notThat's basically how C++ does it with its
const and mutable keywords. In C++ this works well, but I don't think Kotlin has the same ideology.loke
11/01/2025, 7:47 AMfun foo(arg: String? = null) {
val arg = arg ?: "some other value"
// ... use arg here without worrying about using the original value
}