https://kotlinlang.org logo
Title
a

Ayden

09/11/2021, 1:42 AM
As long as we pass the variable as a parameter, it will declare as
val
?
:yes: 1
k

Katrina Eaton

09/11/2021, 1:45 AM
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.
fun someFun(n : Int) {
   val x = n
}
a

Ayden

09/11/2021, 1:58 AM
Thanks Katrina. 😄
😊 1
e

ephemient

09/11/2021, 3:33 AM
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

nkiesel

09/11/2021, 5:04 AM
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)