From the course: Build Spring Boot Apps with the Kotlin Programming Language

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Functions within a class

Functions within a class

- [Narrator] So, so far we've created classes, we've created parameters, we've over-ridden the gets and sets, we've looked at constructors. Now let's look at methods within a class. Or to use the correct Kotlin terminology, functions. Well, you can probably guess that you would create a function in a class just like a function that lives outside of a class. So, for example, if we wanted to create a function that gives us the name in upper case, we could write something like, fun, let's say upper case, name. It's not going to to take any parameters. It is going to return a string. And the implementation would be to return the name dot to upper case. (typing) That will work absolutely fine we can call it-- I don't think I'm going to even bother writing the code that we'll call it. And actually just to tidy this up of course we could write this as a single line expression. We don't need the return type, we can just put an equal sign in and we don't need curly brackets and we don't need…

Contents