我知道一個標準的樂趣就像代碼0如何理解Kotlin中的樂趣?
守則1是從網頁中的示例代碼,我無法理解完全
fun convertFromDomain(forecast: ForecastList) = with(forecast) {...}
爲什麼符號=加入好玩嗎?並且是有趣的convertFromDomain單元的返回值?
代碼0
fun My(forecast: ForecastList):Boolean {
...
return true;
}
代碼1
data class ForecastList(val id: Long, val city: String, val country: String, val dailyForecast: List<Forecast>) {
val size: Int
get() = dailyForecast.size
operator fun get(position: Int) = dailyForecast[position]
}
data class Forecast(val id: Long, val date: Long, val description: String, val high: Int, val low: Int,
val iconUrl: String)
fun convertFromDomain(forecast: ForecastList) = with(forecast) {
val daily = dailyForecast.map { convertDayFromDomain(id, it) }
CityForecast(id, city, country, daily)
}
https://kotlinlang.org/docs/reference/basic-syntax.html#defining-functions,https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/with.html –