I need some help understanding the following code as I am complete Kotlin newbie. This is from a kotlin post I found online
typealias genericContext<T> = Demo<T>.() -> Unit
class Demo<T> {
infix fun doThis(block: genericContext<T>) = block()
fun say(obj: T) = println(obj.toString())
}
fun main(args: Array<String>)
{
val demo = Demo<String>()
demo doThis { say("generic alias") }
}
So I understand that because of the infix
we can skip the usual method call syntax i.e. demo.doThis
and do demo doThis
.
But I don't understand the following:
typealias genericContext<T> = Demo<T>.() -> Unit
This seems to associate the string genericContext<T>
with something that looks like a lambda but I don't get the .()
part. That extends Demo
with a function ()
? I am confused on how this works. Could someone shed some light?