Default parameters

Also, if you observe, each data class has tried to assign some default values to the objects, such as val pollBy : User?=null.

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, say we need to call an API where I want to retrieve either 200 records or whatever value the user has passed, you can only achieve this 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 ...

Get Hands-On Serverless Applications with Kotlin 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.