Wrapping Up
Kotlin doesn’t force you to create methods; you can create top-level functions as well. This opens a few more design choices in Kotlin than Java has—applications aren’t required to comprise of objects only, they can be composed of functions too. This allows you to create procedural, object-oriented, or functional-style code, whichever is a better choice in a given context. The compiler can infer return types for single-expression, non-block functions. The types of parameters are always required, and that’s good.
Default arguments make it a lot easier to extend functions in Kotlin and reduce the need to overload functions. vararg parameters offer the flexibility to pass a discrete number of arguments with type safety, and the spread ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access