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.

Static functions

Static functions

- [Instructor] Now there's one final main topic I'd like to talk about in respect of the classes that we've been working with so far. I'm just going to make this window a bit bigger so we can see the entirety of this class. And that is that, if you remember when we looked at functions, we saw that our functions are static at the top level but they're not static within a class, of course by default, so how would we make a class function static? Well this is, I think, one of the fewer examples where it's slightly more work to do it in Kotlin. I think that's because it's an unusual thing to do in Kotlin. The way you do static functions means you don't generally have to create a function within a class that is static but let's do it and I think what I'd like to do is to create a static factory method for our Another Alternative Customer class that would create a dummy-customer. So it's something with some dummy-data in just for us to work with. I'm assuming you know how to do this in…

Contents