Mark unused parameters in Kotlin

后端 未结 4 1721
青春惊慌失措
青春惊慌失措 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 06:02

    If the functions are part of a class you can declare the containing class open or abstract and the offending methods as open.

    open class ClassForCallbacks {
      // no warnings here!
      open fun methodToBeOverriden(a: Int, b: Boolean) {}
    }
    

    Or

    abstract class ClassForCallbacks {
      // no warnings here!
      open fun methodToBeOverriden(a: Int, b: Boolean) {}
    }
    

提交回复
热议问题