Is there a function in the Kotlin standard library...
# getting-started
c
Is there a function in the Kotlin standard library for that ignores its argument and doesn’t do anything? There have been a few places where I’ve needed to provide a handler to satisfy an API but where I don’t want anything to happen when the handler has been called. I have found myself writing
fun <T> doNothing(param: T): Unit = Unit
or an equivalent lambda and I’m wondering if there is a standard function that I can do in order to not have to write this function myself.
j
If you need to pass a function, you can just pass
{ Unit }
. If you need to implement a method (like an override), you can just use
Unit
as your implementation body
c
Many thanks. I didn’t realise that it’s possible to do something a simple as`{ Unit }` so that might be enough for me 😺
e
even
{ }
should work, although explicitly stating
Unit
is clearer
🙏 1