What does a Kotlin function signature with T.() mean?

前端 未结 3 866
星月不相逢
星月不相逢 2021-01-30 13:00

This is a standard Kotlin function (as far as I know)

inline fun with(t: T, body: T.() -> Unit) { t.body() }

But could anyone write

3条回答
  •  独厮守ぢ
    2021-01-30 13:49

    It's called "Function literals with receiver"

    Function types can optionally have an additional receiver type, which is specified before a dot in the notation: the type A.(B) -> C represents functions that can be called on a receiver object of A with a parameter of B and return a value of C. Function literals with receiver are often used along with these types.

    You can found answer in kotlin offical document:Function literals with receiver

提交回复
热议问题