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
voddan
09/05/2017, 8:45 AM
Since extension extend types, not necessarily classes, those two cases are indeed the same, even on the bytecode level
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.