【发布时间】:2021-04-19 15:27:52
【问题描述】:
在我的 MainActivity 中调用我的 ApiClient 中的函数时,我无法让我的代码作为函数运行,但 intelliJ 说该函数从未使用过。我对 Kotlin 还很陌生,所以这可能是我的语法,但我不完全确定。
这是我的 ApiClient 代码
class ApiClient {
val ITUNES_BASE_URL = "https://itunes.apple.com/"
private var retrofit: Retrofit? = null
fun getClient(): Retrofit? {
if (retrofit == null) {
retrofit = Retrofit.Builder()
.baseUrl(ITUNES_BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
// .client(client)
.build()
}
return retrofit
}
}
这是我调用 getClient 的 MainActivity 的 sn-p
fun displayItunesList() {
val apiService: ApiInterface = ApiClient.getClient().create(ApiInterface::class)
【问题讨论】: