Underscore for unused parameters in functions

For lambdas we can use the underscore character for unused parameters which is very nice.

It would be also very nice to use this feature for normal function parameters:

fun(_ : Executor, query : RfidEntryQuery) {  }

Right now, if I try this syntax I get an error about ‘_’ is reserved for Kotlin which makes it possible to add this feature without much headache (I hope).

The use case that results in this is when I pass a function reference with ‘::’

fun attach(on : HTMLElement, callback : (event : Event) -> Unit)) {  }

fun setup() {
    attach(myElement, ::handler)
}

fun handler(event : Event) {
}

If I don’t use the event in handler I get a warning which is actually useful.

However, to remove the warning, I have to add an annotation which has it’s own problems:

  • depending where the programmer puts the suppress may lead to future errors (to wide suppress means possible problems remain hidden)
  • it hurts readability
1 Like

It looks kind of similar to the ticket I posted before: KT-17746.

1 Like

Yes, it is basically the same.