Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting retrofit exception Method return type must not include a type variable or wildcard in kotlin

 networkCall = NetworkCall(context)
            val responceCall = networkCall!!.getRetrofit(true).callReadMeService()
            responceCall.clone().enqueue(object : Callback<BaseResponse<*>?> {
                override fun onResponse(call: Call<BaseResponse<*>?>, response: Response<BaseResponse<*>?>) {
                    networkCall!!.dismissLoading()


                    web_view!!.loadData((response.body()?.data as LinkedTreeMap<*, *>)["description"] as String, "text/html", "UTF-8")
                }

                override fun onFailure(call: Call<BaseResponse<*>?>, t: Throwable) {
                    networkCall!!.dismissLoading()

                }
            })

here is api method

@POST("stories/readme")
fun callReadMeService():   Call<BaseResponse<*>?>

now i am getting this exception

here is my BaseResponse class

class BaseResponse<T> {

    var message: String? = null
    var status: Boolean = false
    var errors: Array<String>? = null
    var code: String? = null
    var data: T? = null
}

Method return type must not include a type variable or wildcard: retrofit2.Call> for method IApi.callReadMeService

now i can't remove generic data variable from BaseResponse class, cause i am using this class as a common Api parser

any solution for this

like image 513
pkgrover Avatar asked Aug 31 '17 09:08

pkgrover


1 Answers

You cannot do this, because the type info needs to be fully specified, otherwise retrofit cannot correctly generate the Service. See this discussion.

You need to create a different API method for each type.

like image 170
kenny_k Avatar answered Sep 24 '22 11:09

kenny_k