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
From the course: Build Spring Boot Apps with the Kotlin Programming Language
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Project structure and packages2m 5s
-
(Locked)
The class declaration and class-level attributes3m 31s
-
Instantiating a class and accessing class-level attributes2m 14s
-
(Locked)
Creating a simple constructor5m 7s
-
(Locked)
Secondary constructors5m 20s
-
(Locked)
Alternative class design5m 3s
-
(Locked)
Overriding getters and setters7m 21s
-
(Locked)
Functions within a class2m 57s
-
(Locked)
Static functions3m 28s
-
(Locked)
Data classes7m 32s
-
(Locked)
-
-
-
-
-
-
-
-
-
-
-
-
-
-