Mark unused parameters in Kotlin

后端 未结 4 1720
青春惊慌失措
青春惊慌失措 2020-12-14 05:40

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

4条回答
  •  心在旅途
    2020-12-14 05:45

    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

提交回复
热议问题