Hello JetBrains. It’s one of you’re Kotlin programmer. I wanted to bring to notice that functions in Kotlin take their arguments in ‘val’ value and not ‘var’ value. This won’t let us do any operation on the arguments of function or use them in an operation inside the function. Most of the programming language don’t show such kind of behavior. If possible please look into the matter as this very important in terms of programming and android development perspective.
This topic has already been discussed on this forum.
The consensus seem to be that method parameters should be final to avoid introducing hard to detect bugs in the code.
Thats probably not going to change. It like making classes final is a tool to prevent bad coding practices. If you want to modify a parameter you should make a copy then do work on the copy.
Note that you can introduce a non-final variable with the same name as the argument. This is quite useful, as it will prevent accidental usage of the wrong name.
fun foo(bar: String) {
var bar = bar
// now bar is mutable
}
1 Like