https://kotlinlang.org logo
#stdlib
Title
# stdlib
l

Leon Linhart

05/02/2020, 10:48 PM
What about a function
inline 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/554
d

Derek Peirce

05/03/2020, 12:08 AM
I think it would be simple enough for you to create your own extension function that aliases to
apply
when you really need it.
2 Views