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?
You can also use @Suppress in Kotlin or @SuppressWarnings in Java. To suppress a lint warning with a comment, add a //noinspection id comment on the line before the statement with the error.
Reports the parameters that are considered unused in the following cases: The parameter is passed by value, and the value is not used anywhere or is overwritten immediately. The parameter is passed by reference, and the reference is not used anywhere or is overwritten immediately.
1 Answer. Show activity on this post. Adding @Suppress("UNCHECKED_CAST") (also possible through IDEA's Alt + Enter menu) to any of statement, function, class and file should help.
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:
If your parameter is in a lambda, you can use an underscore to omit it. This removes the unused parameter warnings. It will also prevent IllegalArgumentException
in the case that the parameter was null and was marked non-null.
See https://kotlinlang.org/docs/reference/lambdas.html#underscore-for-unused-variables-since-11
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With