Hi to all! How I can shadow unused function argume...
# announcements
d
Hi to all! How I can shadow unused function argument?
g
Only by suppressing this warning for this argument or for this function
why do you need this unused argument?
d
I set this function on clickListeners
k
Maybe if you call it
_
?
1
d
I can use lambdas, but (i think) this syntax more friendly and works faster
g
For click listener it’s different, you can use
_
for lamba params, but not for function params
k
But what if you're implementing an interface for example? Is the warning surpressed automatically then?
d
yes, _ , __, _ - reserved words
g
I would just use lambda instead of adding useless param, imo it’s bad style to add useless params for such case
yes, _ , __, _ - reserved words
For function params, not for lambda arguments
1
why not just use:
setOnClickListener { logic.okPress() }
yes, method reference is more idiomatic, but if you need add useless param, I would say that it’s become much less idiomatic
d
too many brackets)
g
one more sulution to add custom
setOnClickListener
extension function without argumentyt
Copy code
fun View.onClick(action: () -> Unit)
so you can now use it with functions without arguments: button.onClick(logic::okPress)
or even with the same name:
Copy code
inline fun View.setOnClickListener(crossinline listener: () -> Unit) {
    setOnClickListener { listener() }
}
d
apparently, this is the only way
g
so now you can use it with method reference without additional changes
d
but i add one lambda
g
No, function is inlined, no overhead in this case
d
thanks)