Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin: explicitly unnamed function arguments

@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.

like image 265
GlenPeterson Avatar asked Jun 04 '18 00:06

GlenPeterson


1 Answers

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.

like image 97
yole Avatar answered Oct 17 '22 00:10

yole