Named parameters

In Kotlin, we can call/bind a parameter with their name for any function. We can call the preceding function by interchanging the parameter sequence as well. Something like the following:

    showDetailedForecast(forecast = forecast, city =     forecastResult.city)

Observe that we swapped the place of the variable. And no wonder, all CSS classes that we have applied so far have a named parameter. Check all previous <div>, <h>, and <p> tags. Consider the following examples:

    val weatherDetailDiv = document.create.div(classes =        "detailsContainer")
    button(classes = "getWeatherButton")
    span(classes = "primaryText") { +"${Math.round(max)} °C" }

Get Kotlin Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.