Mark unused parameters in Kotlin

TheTeaMan picture TheTeaMan · Mar 14, 2015 · Viewed 32.7k times · Source

I am defining some functions to be used as callbacks and not all of them use all their parameters.

How can I mark unused parameters so that the compiler won't give me warnings about them?

Answer

bashor picture bashor · Mar 14, 2015

With the @Suppress annotation You can suppress any diagnostics on any declaration or expression.

Examples: Suppress warning on parameter:

fun foo(a: Int, @Suppress("UNUSED_PARAMETER") b: Int) = a

Suppress all UNUSED_PARAMETER warnings inside declaration

@Suppress("UNUSED_PARAMETER")
fun foo(a: Int,  b: Int) {
  fun bar(c: Int) {}
}

@Suppress("UNUSED_PARAMETER")
class Baz {
    fun foo(a: Int,  b: Int) {
        fun bar(c: Int) {}
    }
}

Additionally IDEA's intentions(Alt+Enter) can help you to suppress any diagnostics: