Hey everyone, Is there any difference between defi...
# getting-started
e
Hey everyone, Is there any difference between defining the extention function on the concrete base class as opposed to defining it on a generic subclass ? Semantically, to me, they dont look any different
fun Context.dpToPx(dp: Int) = ...
vs
fun <T: Context> T.dpToPx(dp: Int) = ...
v
Since extension extend types, not necessarily classes, those two cases are indeed the same, even on the bytecode level
e
Yeah thanks.
r
If you plan on returning the receiver, or if the function takes a function type as an argument, the latter is usually more useful. Otherwise there's no difference.