As long as we pass the variable as a parameter, it...
# getting-started
a
As long as we pass the variable as a parameter, it will declare as
val
?
👌 1
k
I don't know the answer to your question, but I do know the code that has worked for me is to assign n to a val within the method.
Copy code
fun someFun(n : Int) {
   val x = n
}
a
Thanks Katrina. 😄
😊 1
e
https://kotlinlang.org/spec/declarations.html#function-declaration
parameters are final and cannot be changed inside the function
🙏 2
effectively equivalent to
val
, yes
n
if you really have to modify the value, use
var n = n
inside the function which creates a local variable with the same name, shadowing the parameter. But generally, this is not good style because it makes it appear as if you can modify the parameter (which you can not as @ephemient explained)