Default parameter

Often we end up writing a lot of overloaded methods and method chaining because we want to perform something extra with different values.

For example, if I say we need to call an API where I want to retrieve either 200 records or whatever value the user has passed. So this you can only achieve by writing two function calls.

But Kotlin has a feature where if no parameter is passed Kotlin picks up the default value if specified, thus overloaded methods can be drastically reduced. The following is the code where you can see how we used default parameters and it's one of the common use cases that is faced by every developer:

    @GET("/1.1/statuses/home_timeline.json")     fun showHomeTimeline(@Query("count") count: Int = 200):    

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.