jake talledo
jake talledo

Reputation: 610

How to pass Generic Interface T to function with class reference as parameter

I have a Generic Interface for retrofit2 http request

interface BaseGetRequest<T: Any>  {
@GET fun requestGet(@Url urlGetRequest: String,@FieldMap parameters: Map<String, String>): Single<T>
}

and now I need to pass the BaseGetRequest to retrofit2 as class reference, in java this is just treated as BaseGetRequest.java, but does not allow in kotlin because it says type mismatch.

enter image description here

Createenter image description here

How do I solve this?

Upvotes: 0

Views: 549

Answers (1)

Andrey Danilov
Andrey Danilov

Reputation: 6612

Basically you should return type that you want to get as response.

If you do not need result I would recommend to use Completable instead of Single.

But if you need single guess you can write just:

NetworkUtils.builder().create(BaseRequest::class.java)

without any diamond operator

Upvotes: 1

Related Questions