[英]Type mismatch. Required: Nothing Found: Callback<*>
In my android project: 在我的android项目中:
import retrofit2.Call
import retrofit2.Callback
fun getAdvertising(callback: Callback<List<Advertising>>) {
val call = tangoRestClient.advertising
executeAsync(call, callback)
}
private fun executeAsync(call: Call<*>, callback: Callback<*>) {
call.enqueue(callback) // compile error
}
But I get compile error: 但是我得到了编译错误:
> Task :app:generateDebugSources
> Task :app:validateSigningDebug
> Task :transport:compileDebugKotlin FAILED
e: \TransportService.kt: (127, 14): Out-projected type 'Call<*>' prohibits the use of 'public abstract fun enqueue(p0: Callback<T!>!): Unit defined in retrofit2.Call'
FAILURE: Build failed with an exception.
Yep, the type parameter of Call
and Callback
should be the same. 是的, Call
和Callback
的类型参数应该相同。 You have to write your executeAsync
function for example like this: 您必须像下面这样编写您的executeAsync
函数:
private fun <T> executeAsync(call: Call<T>, callback: Callback<T>) {
call.enqueue(callback) // no compile error
}
It will guarantee that type parameters are the same 它将保证类型参数相同
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.