简体   繁体   English

类型不匹配。 必需:找不到:回调<*>

[英]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. 是的, CallCallback的类型参数应该相同。 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.

相关问题 将 Java 转换为 Kotlin:类型不匹配。 必需:MenuSlidingTabStrip.OnTabSelectedListener? 找到:(无,无)→Boolean - Converting Java To Kotlin: Type mismatch. Required: MenuSlidingTabStrip.OnTabSelectedListener? Found: (Nothing, Nothing) → Boolean 类型不匹配。 必需:片段,找到:PlaceAutocompleteFragment - Type mismatch. Required: Fragment, Found: PlaceAutocompleteFragment 类型不匹配。 要求:观察员<in Int!>成立:? - Type mismatch. Required: Observer<in Int!> Found:? 类型不匹配。 必需:找到的上下文:在片段中 - Type mismatch. Required: Context Found: In Fragment 类型不匹配。 必需:ContentResolver! 找到:整数 - Type mismatch. Required: ContentResolver! Found: Int 类型不匹配。 必需:数组 <Uri> ! 找到:数组 <Uri?> - Type mismatch. Required: Array<Uri>! Found: Array<Uri?> 类型不匹配。 必需: suspend () → Response&lt;*&gt; 找到:Response<Void> - Type mismatch. Required: suspend () → Response<*> Found: Response<Void> 类型不匹配。 必需:字符串:找到:Int 错误 - Type mismatch. Required: String! Found: Int error 类型不匹配。 必需:结果<newsresponse> : 发现: 结果<response<newsresponse> &gt;? </response<newsresponse></newsresponse> - Type mismatch. Required: Result<NewsResponse>! Found: Result<Response<NewsResponse>>? 类型不匹配。 必需:FirebaseRecyclerAdapter<chatobject, chatvoiceviewholders> ? 成立:</chatobject,> - Type mismatch. Required: FirebaseRecyclerAdapter<ChatObject, ChatVoiceViewHolders>? Found:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM