ait
04/22/2019, 11:01 AMCzar
04/22/2019, 11:02 AMait
04/22/2019, 11:03 AMCzar
04/22/2019, 11:03 AMait
04/22/2019, 11:04 AMvach
04/22/2019, 11:05 AMvach
04/22/2019, 11:05 AMvach
04/22/2019, 11:05 AMvach
04/22/2019, 11:06 AMshow kotlin bytecode
actionCzar
04/22/2019, 11:06 AMkotlin.jvm.functions.Function1
, so this code when compiled is resulting in the same method signature in the bytecodevach
04/22/2019, 11:06 AMCzar
04/22/2019, 11:07 AMvach
04/22/2019, 11:11 AMCzar
04/22/2019, 11:13 AMait
04/22/2019, 11:13 AMCzar
04/22/2019, 11:15 AM@JvmName("someOtherName")
on one of your functions.ait
04/22/2019, 11:20 AM@JvmName
Czar
04/22/2019, 11:22 AMait
04/22/2019, 11:23 AMinline fun <T> T.use(function: T.() -> Any?): T {
this.function()
return this
}
@JvmName("someOtherName")
inline fun <T> T.use(function: (T) -> Any?): T {
function(this)
return this
}
ait
04/22/2019, 11:23 AMMarko Mitic
04/22/2019, 11:24 AMCzar
04/22/2019, 11:35 AMinline
. I guess we're missing something.ait
04/22/2019, 11:36 AMMarko Mitic
04/22/2019, 11:36 AMCzar
04/22/2019, 11:41 AMT.() -> Any?
can in fact be called both ways, Kotlin does not know what to use there, so the problem happens before compiler even gets to @JvmName
Which on the other hand also means, you could dispense with function2
variant altogether and just have function1
and call it however you like 🙂Marko Mitic
04/22/2019, 11:43 AMT.()
looks to be just syntax sugar over (T)
Dominaezzz
04/22/2019, 11:44 AMfunction1(t)
was allowed.Czar
04/22/2019, 11:45 AMT.()
is "_parent_" of (T)
they're not strictly equivalent, as you cannot use function2
both ways while function1
- you can.elizarov
04/22/2019, 11:46 AMT.() -> Any?
is the same as functional type (T) -> Any?
. Both are syntactic sugar over Funtion1<T, Any?>
Dominaezzz
04/22/2019, 11:46 AMelizarov
04/22/2019, 11:47 AMelizarov
04/22/2019, 11:50 AMfun String.(): Int
and fun (x: String): Int
in the same scope, but you can solve it with @JvmName
Dominaezzz
04/22/2019, 11:52 AMfunction1(t)
will work for fun T.function1(): Any? { TODO() }
.elizarov
04/22/2019, 11:52 AMelizarov
04/22/2019, 11:54 AMDominaezzz
04/22/2019, 11:58 AMait
04/22/2019, 11:58 AMkarelpeeters
04/22/2019, 12:39 PM(T) -> X
to something expecting T.() -> X
, because in the end there's no conceptual difference, it's only cosmetic.elizarov
04/22/2019, 1:59 PM