Dagger 2 doesn't recognize provide method in Kotlin. Java works fine

Viewed 899

Dagger doesn't recognize one provided method in Kotlin. This is the important part of the module:

    @Provides
    @AppScope
    fun provideClient(cache: Cache, interceptors: List<Interceptor>?): OkHttpClient {

        val httpBuilder = OkHttpClient.Builder()

        interceptors?.let {
            for (interceptor in interceptors) {
                httpBuilder.addInterceptor(interceptor)
            }
        }

        return httpBuilder
                .cache(cache)
                .build()
    }

    @Provides
    @AppScope
    fun provideInterceptors(): List<Interceptor>? {
        return listOf(HttpLoggingInterceptor().setLevel(WebServiceConfig.LOGGING_LEVEL))
    }

The error message is as follows:

AppComponent.java:15: error: java.util.List<? extends okhttp3.Interceptor> cannot be provided without an @Provides-annotated method.

If I use MutableList, then it works. Therefore the question is: what is the problem with List in Dagger2 / Kotlin?

1 Answers
Related