From the course: Kotlin Essential Training: Functions, Collections, and I/O

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Basic functions

Basic functions

- [Narrator] How do we write self-contained reusable pieces of code that we can then invoke and reuse throughout our code bases? Well, in Kotlin we start with functions. In Kotlin functions are first class concepts. We can write and use functions without any kind of enclosing class, struct, or other obstruction. Because of this, functions in Kotlin are incredibly flexible and important. So let's start by building up our understanding of function basics. Here in IntelliJ, we have an example of our first real function. This function is our main function. We've been running this repeatedly. And in this example, it's going to print out the string hello world to the console as we've seen before. Now, let's walk through the key elements of this first function. So first off we have the fun keyword. This represents a function. This is how we know that what we are defining is going to be a function. Then we have the…

Contents