在 ClientModule.kt
@Singleton
@Provides
fun provideClient(application: Application, configuration: OkhttpConfiguration?,
sslConfiguration: SSLConfiguration?, cookieJarConfiguration: CookieJarConfiguration?, builder: OkHttpClient.Builder, intercept: Interceptor,
interceptors: List<Interceptor>?, handler: GlobalHttpHandler?): OkHttpClient{...}
在 AppModule.kt 中
@Singleton
@Provides
fun provideInterceptors(): List<Interceptor>? {
return mInterceptors
}
错误消息是:
e: /Users/xiaoqidong/AndroidStudioProjects/DemoKotlin/framework/build/tmp/kapt3/stubs/debug/com/bnpparibas/framework/di/component/AppComponent.java:23: error: java.util.List<? extends okhttp3.Interceptor> cannot be provided without an @Provides-annotated method.
public abstract okhttp3.OkHttpClient okHttpClient();
^
java.util.List<? extends okhttp3.Interceptor> is injected at
com.bnpparibas.framework.di.module.ClientModule.provideClient(…, interceptors, …)
okhttp3.OkHttpClient is provided at
com.bnpparibas.framework.di.component.AppComponent.okHttpClient()
太奇怪了,生成的 java 文件将我的函数签名从 List<Interceptor> 更改为 List
以下是生成的文件:
@Override
public OkHttpClient get() {
return Preconditions.checkNotNull(
module.provideClient(
applicationProvider.get(),
configurationProvider.get(),
sslConfigurationProvider.get(),
cookieJarConfigurationProvider.get(),
builderProvider.get(),
interceptProvider.get(),
interceptorsProvider.get(),
handlerProvider.get()),
"Cannot return null from a non-@Nullable @Provides method");
}
public static Factory<OkHttpClient> create(
ClientModule module,
Provider<Application> applicationProvider,
Provider<ClientModule.OkhttpConfiguration> configurationProvider,
Provider<ClientModule.SSLConfiguration> sslConfigurationProvider,
Provider<ClientModule.CookieJarConfiguration> cookieJarConfigurationProvider,
Provider<OkHttpClient.Builder> builderProvider,
Provider<Interceptor> interceptProvider,
Provider<List<? extends Interceptor>> interceptorsProvider,
Provider<GlobalHttpHandler> handlerProvider) {
return new ClientModule_ProvideClientFactory(
module,
applicationProvider,
configurationProvider,
sslConfigurationProvider,
cookieJarConfigurationProvider,
builderProvider,
interceptProvider,
interceptorsProvider,
handlerProvider);
}
}
如何阻止 kapt 更改我的函数签名?