Kotlin: explicitly unnamed function arguments
Asked Answered
L

1

9
@FunctionalInterface
interface Fn2<A, B, R> : BiFunction<A, B, R>, (A, B) -> R {
    @JvmDefault
    override operator fun invoke(p1: A, p2: B): R {
        ...

When I implement this interface:

object: Fn2<Int,Int,Int> {
    override fun invokeEx(accum: Int, i: Int): Int =
    accum + i
}

I get a warning:

Warning:(598, 76) Kotlin: The corresponding parameter in the supertype 'Fn2' is named 'a'. This may cause problems when calling this function with named arguments.

Is there some kind of annotation or keyword or secret name (like it or _) that I can use on the invoke() function definition to get rid of these warnings. I admit I'm doing something kind of non-standard with Java/Kotlin interop that might go away when I finish refactoring, but I'm still curious.

I know there's a @Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") (thank you evilbloodydemon) but I'm looking for a way to suppress it at the function signature that I'm overriding, not at the implementation.

Link answered 4/6, 2018 at 0:35 Comment(1)
youtrack.jetbrains.com/issue/KT-9872Bustard
G
7

As of Kotlin 1.2.40, there is no possibility to mark a function argument as explicitly unnamed, and I'm not aware of any plans to add such a possibility.

Gamber answered 4/6, 2018 at 11:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.