[Kotlin] I don't know what T.() means in the apply function

Asked 2 years ago, Updated 2 years ago, 91 views

fun <T> test(block: (T) -> Unit) {

}
fun <T> test(block: T.() -> Unit) {

}

I'm studying libraries like apply() and also() in Cotlin But I don't understand T.() here.

The first one makes sense. T is received as a parameter and used within the lambda block, right?

That is, what can be used as it.

But I don't really understand the second one.

I don't know what T.() means. I don't really understand what it's delivering as a factor.

If it's a Lambda-style parameter, it should be (T)() -> Unit but this makes an error.

block: Int() -> Unit I tried it like this, but I don't know what it means.

kotlin

2022-09-20 15:58

1 Answers

It would be helpful if you refer to it ... https://kotlinlang.org/docs/extensions.html

......


2022-09-20 15:58

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.