does kotlin script support automatic SAM conversio...
# gradle
m
does kotlin script support automatic SAM conversion ? I get an error when I do
val action = Action<String> { println(it) }
b
Action<T>
is treated specially in build scripts and in projects using the
kotlin-dsl
plugin
Whereas a regular SAM interface with a
fun execute(target: T): Unit
would be treated as
(T) -> Unit
,
Action<T>
is treated as
T.() -> Unit
m
Ok thanks, time for me to dig in the Kotlin documentation !
Just curious: what is that for ?
b
This is so the
it.
qualifier is not needed when interacting with
Action<T>
based Gradle APIs, for instance, `Project.copy(Action<CopySpec>)`:
Copy code
copy {
   from(“source”) // no `it.from`
   into(“target”)
}
m
I see
b
Your snippet could be rewritten as:
Copy code
val action: Action<String> = Action { println(this) }
action.execute("fooBar!")
m
Works fine, thanks 🙂
I was tryring to call plugins.all {}. Removing
it
works fine
b
👍