Summary
In this chapter, we've seen how to define and use functions. We learned how functions can be defined at the top-level or inside other functions. There was also a discussion on different features connected to functions: vararg parameters, default names, and named argument syntax. Finally, we saw some Kotlin special return types: Unit
, which is the equivalent of Java's void
, and Nothing
, which is a type that cannot be defined and means that nothing can be returned (only exceptions).
In the next chapter, we are going to see how classes are defined in Kotlin. Classes are also specially supported by the Kotlin language, and there are lots of improvements introduced over Java definitions.