'how to use default parameter in retrofit GET Request with method reference expression(double colon expression)
now i refactoring my codes. and i try to use method reference expression to retrofit Get Rquest methods. but it can't be use default parameter. why? somebody has any solutions?
// WebServer.kt
interface WebServer{
@GET("info/list/week")
fun getWeekTrendingInfo(
@Query("language") language: String = "en-US",
@Header("authKey") authKey: String = ${BuildConfig.API_KEY}
): Call<InfoDTO>
@GET("info/list/day")
fun getDailyTrendingInfo(
@Query("language") language: String = "en-US",
@Header("authKey") authKey: String = ${BuildConfig.API_KEY}
): Call<InfoDTO>
}
// MainActivity.kt
override fun onCreate(savedInstanceState: Bundle?) {
...
loadTrendingInfos(isWeek)
}
private fun loadTrendingInfos(isWeek: Boolean) {
webService.run{
val api = if (isWeek) this::getWeekTrendingInfo else this::getDailyTrendingInfo
api().enqueue(InfoCallback { _, response -> // ERROR! IDE say No value passed for parameter
adapter.submitList(response.body().infoList)
})
}
}
when i call api( ) in mainActivity's loadTrendingInfos function(not include param. cuz i want use default params), IDE say to me No value passed for parameter 'p1', No value passed for parameter 'p2'
and val api's type is
val api: KFunction2<String, String, Call<InfoDTO>>
so i try call api( ) like this (include param. not use default param)
api("en-US", "${BuildConfig.API_KEY}").enqueue(InfoCallback { _, response ->
adapter.submitList(response.body()?.movieList)
})
it work!
but i want know why can't use default parameter? and how to use default parameter this one?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
