【发布时间】:2018-09-07 18:36:05
【问题描述】:
我不知道为什么我在写这个 kotlin 代码时会遇到这样的问题
Log.d(TAG, msg:"onCreate called. Score is :$score")
【问题讨论】:
-
删除 "msg:" -> Log.d(TAG, "onCreate called. Score is :$score")
我不知道为什么我在写这个 kotlin 代码时会遇到这样的问题
Log.d(TAG, msg:"onCreate called. Score is :$score")
【问题讨论】:
我假设您尝试使用命名参数,判断我的 msg 是 Log.d 中第二个参数的名称,并且它与您的代码匹配。但是,您确实有两个问题:
=,而不是:
你可以这样做:
data class SomeClass(val x: String, val y: String)
fun someFunction(){
SomeClass(y = "y", x = "x")
}
但你不能为Log.d 这样做,因为它不是 Kotlin 函数。作为参考,这是适当的语法:
Log.d(TAG, msg="onCreate called. Score is :$score")
但它不会编译,因为Named arguments are not allowed for non-Kotlin functions。所以删除它。您不能在该方法中使用命名参数。
【讨论】:
去掉“味精:”
Log.d(TAG, "onCreate called. Score is :$score")
【讨论】:
尝试使用 Log.d(TAG, "msg:onCreate called. Score is :$score")
【讨论】: