Hi all, what would you choose? ``` inline fun View...
# android
Hi all, what would you choose?
Copy code
inline fun View.onClick(crossinline l: (v: View) -> Unit) = setOnClickListener { l(it) }

inline fun View.onClick(noinline l: (v: View) -> Unit) = setOnClickListener(l)
The first one is optimized but doesn't gives you a proper stacktrace for the
lambda in case you want it, if you get an exception for example. The second one generates 2 classes instead of one, and has 3 methods calls instead of one when a click strikes, but you see it all in the stacktrace, with the exception source. Note that the second one still produces meaningful method and class names. Just the line number is plain wrong and misleading (not hard to figure out you can't trust it).
1️⃣ 2
Or maybe you can just debuging with
and change that into
when you want to release?
@w_bianrytree That's a nice suggestion! However, I'm afraid I can't take advantage of it as this code will be put in a library
I think 1 is right since I hope most use mvvm or mvp and don't put much logic in the onClicks... so any ways it will be delegated (then with 2 you'd have 4 method calls...).