Kotlin 方法前的加号是什么意思?
What's the meaning of plus sign before a Kotlin method?
我正在研究 Kotlin 并正在观看 AndroidDevSummit,更具体地说是来自 Leland Richardson 的演讲"Undestanding Compose"。
在演示时(28 分 26 秒),他展示了以下代码:
@Composable
fun App(items: List<String>, query: String) {
val results = +memo(items, query) {
items.filter { it.matches(query) }
}
// ...
}
"memo"方法前的“+”加号是什么意思?
+
is kind of like an operator invoke for effects. The functions
that return effects just return an object for the effect and the +
says, "add it into the composition here"
亚当·鲍威尔发表于 Kotlin Slack
The full thread on kotlin slack
以后会去掉+
运算符,对于状态来说,可能会使用属性代表,像这样:var myState by state { "value" }
我正在研究 Kotlin 并正在观看 AndroidDevSummit,更具体地说是来自 Leland Richardson 的演讲"Undestanding Compose"。
在演示时(28 分 26 秒),他展示了以下代码:
@Composable
fun App(items: List<String>, query: String) {
val results = +memo(items, query) {
items.filter { it.matches(query) }
}
// ...
}
"memo"方法前的“+”加号是什么意思?
+
is kind of like an operator invoke for effects. The functions that return effects just return an object for the effect and the+
says, "add it into the composition here"
亚当·鲍威尔发表于 Kotlin Slack
The full thread on kotlin slack
以后会去掉+
运算符,对于状态来说,可能会使用属性代表,像这样:var myState by state { "value" }