test opty
11/06/2024, 7:45 AMRob Elliot
11/06/2024, 8:18 AMString
) then you won’t be able to mutate the value it references, if it’s mutable (like MutableList
) then you will.test opty
11/06/2024, 3:02 PMfun foo(val a:Int) = a + 2;
test opty
11/06/2024, 3:04 PMRob Elliot
11/06/2024, 3:05 PMfun foo(a: Int) = a + 2
but a
will not be reassignable, which is all that using val
when defining a variable does)test opty
11/06/2024, 3:07 PMRob Elliot
11/06/2024, 3:09 PMfun foo(a: Int): Int {
var a = a
a = a + 2
return a
}
test opty
11/06/2024, 3:12 PMKlitos Kyriacou
11/06/2024, 3:19 PMAh, so function parameters are const by default.Not just by default. They are always non-reassignable. (I wouldn't use the term "const" as that is a keyword that can only be used in certain contexts.) Unlike C, C++ and C#, you can never reassign a parameter inside a function.