我正在尝试使用Retrofit作为学习型Kotlin的实践在Kotlin中创建一个小示例。 但是,此行:
Observable<Model.Result>//No type argument expected for class observable
请参考下面发布的代码以及gradle文件的内容,请让我知道如何解决此错误。 我使用以下链接作为参考,以学习如何在Kotlin中使用翻新
对象:
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)
}
}
}
渐变
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"
}