Как установить Observable типа Object в качестве возвращаемого значения метода в интерфейсе - PullRequest
0 голосов
/ 09 июля 2019

Я пытаюсь создать небольшой пример в kotlin, используя Retrofit в качестве практики в изучении Kotlin.Тем не менее, эта строка:

    Observable<Model.Result>//No type argument expected for class observable

, пожалуйста, обратитесь к приведенному ниже коду, а также к содержимому файла Gradle, и, пожалуйста, дайте мне знать, как исправить эту ошибку.я использовал следующую ссылку, чтобы узнать, как использовать Retrofit с Kotlin

Object :

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

WikiService :

interface WikiApiService {
@GET("api.php")
fun hitCountCheck(@Query("action") action: String,
                  @Query("format") format: String,
                  @Query("list") list: String,
                  @Query("srsearch") srsearch: String):
        Observable<Model.Result>//No type argument expected for class observable


//why do we need a companion object
companion object {
    fun create(): WikiApiService {
        val retrofit = Retrofit.Builder()
            .addCallAdapterFactory(
                RxJava2CallAdapterFactory.create())
            .addConverterFactory(
                GsonConverterFactory.create())
            .baseUrl("https://en.wikipedia.org/w/")
            .build()
        return retrofit.create(WikiApiService::class.
            java)
    }
}
}

gradle

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

implementation "com.squareup.retrofit2:retrofit:2.3.0"
implementation "com.squareup.retrofit2:adapter-rxjava2:2.3.0"
implementation "com.squareup.retrofit2:converter-gson:2.3.0"
implementation "io.reactivex.rxjava2:rxandroid:2.0.1"
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...