Default parameter not recognized at call site, when a Function1 with generic parameter is used


#1

The following code should compile.

class Foo{
    fun <T: Runnable >start(callback:  ( T) -> Unit = {}){
    }

    fun test(){
        start() //doesn't compile
    }
}

Compiler Error:

Type inference failed: Not enough information to infer parameter T in

fun start> (> callback: (T) → Unit = …> ) : Unit

Please specify it explicitly.

Kotlin 1.2.21


#2

KT-5464 has a longer discussion on where Kotlin requires generic parameters (and Java doesn’t). The discussion also references other similar issues.