How to return Observable of type object from a method in the interface

[亡魂溺海] 提交于 2019-12-11 14:03:41

问题


I am learning kotlin. as shown in the code below, i created a object Model and an interface. the method in the interface should return

Model.Result

but when I wrap the aforementioned data type in Observable I receive the following error

No type argument expected for class observable

please let me know how fix this issue...as i tried to find some solution in google but it does not work

Object:

public object Model {
data class Result(val query: Query)
data class Query(val searchinfo: SearchInfo)
data class SearchInfo(val totalhits: Int)
}

interface:

interface WikiService {
fun method1(): Observable<Model.Result>//No type argument expected for class observable

回答1:


Can you show imports? You have probably imported wrong Observable class. I think you are using RxJava2 so the import should be import io.reactivex.Observable




回答2:


You are using java.util.Observable that doesn't accept any paramter.

You should import io.reactivex.Observable that is parametrized.



来源:https://stackoverflow.com/questions/56950569/how-to-return-observable-of-type-object-from-a-method-in-the-interface

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!