final 或 val 函数参数还是在 Kotlin 中? [英] final or val function parameter or in Kotlin?
本文介绍了final 或 val 函数参数还是在 Kotlin 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么 Kotlin 删除了在 Java 中非常有用的 final 或 val 函数参数?
Why does Kotlin removed the final or val function parameter which is very useful in Java?
fun say(val msg: String = "Hello World") {
msg = "Hello To Me" // would give an error here since msg is val
//or final
...
...
...
}
推荐答案
Kotlin 函数参数是最终的.没有 val 或 final 关键字,因为这是默认值(并且无法更改).
Kotlin function parameters are final. There is no val or final keyword because that's the default (and can't be changed).
这篇关于final 或 val 函数参数还是在 Kotlin 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文