https://kotlinlang.org logo
Title
d

david.bilik

02/23/2018, 12:37 PM
does Kotlin Native supports generics? I am playing a little with multiplatform project and I have this in common module
interface ApiCallback<in T> {
    fun onSuccess(data: T)
    fun onError(error: Throwable)
}
and then I have some class
expect class Api {
    fun login(email: String, password: String, callback: ApiCallback<LoginResponse>)
}
and when I try to build with
compileKonan
command, it fails on
src/main/kotlin/model/Api.kt:10:21: error: actual function 'login' has no corresponding expected declaration
The following declaration is incompatible because parameter types are different:
    public final expect fun login(email: String, password: String, callback: ApiCallback<LoginResponse>): Unit

    actual fun login(email: String, password: String, callback: ApiCallback<LoginResponse>) {
                    ^
src/main/kotlin/model/Api.kt:10:77: error: unresolved reference: LoginResponse
    actual fun login(email: String, password: String, callback: ApiCallback<LoginResponse>) {
                                                                            ^
other methods work.. so my only guess is this this generic class
o

olonho

02/23/2018, 4:45 PM
Yes, generics are supported. Does your code work on Kotlin/JVM?
d

david.bilik

02/23/2018, 4:48 PM
Yup, the problem was the missing import 🙂