Leon Linhart
05/02/2020, 10:48 PMinline fun <T> __apply(receiver: T, block: T.() -> Unit): T
(name tbd) which behaves excactly like the current`apply`.
Reasoning: When using Java libraries I tend to avoid extension functions with "simple" names (such as apply
, run
, let
, etc.) since it is always possible that a method with the same name is added to a class in a Java library. Due to Kotlin's resolution rules this could easily result in a source-incompatible change (depending on the exact method signature). However, with __apply(object)
this would not be a problem. Additionally, there is already a similar pattern in the stdlib: with
and run
. (See also https://kotlinlang.org/docs/reference/scope-functions.html#function-selection)
Bonus "real-world example": https://github.com/LWJGL/lwjgl3/issues/554Derek Peirce
05/03/2020, 12:08 AMapply
when you really need it.