Hello! If I have a function that takes a callback ...
# announcements
s
Hello! If I have a function that takes a callback that is called with a parameter, and for some callback I do not need or use this parameter – the only way to not get warnings about this is to use a @Suppress annotation, is this correct?
Copy code
fun myCallback(@Suppress("UNUSED_PARAMETER") someValue: Int) { }
It seems I can only use
_
in a lambda...
n
@Simon Kågedal Reimer that thing is really long and ugly, so potentially an alternative is to write a function, named whatever you want, that's generic and takes an argument, and uses that suppress directive
Then you can suppress warnings by calling the noop function
s
Right! Yes, I agree that it's ugly. That's a pragmatic suggestion, if there are no better language constructs for this – I was surprised that you couldn't use
_
in this situation. I now did this simple thing:
Copy code
fun Any.ignore() {}
Thanks for the suggestion!
👍 1