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.
Using immutable lists
From the course: Build Spring Boot Apps with the Kotlin Programming Language
Using immutable lists
- [Instructor] Let's have a look at now at the customer database object. So let's create a reference for that. I think I'll just call this one db. So we can instantiate it fine and if I do db dot I see we get a get customers. But that's really the only method. Obviously we can't set the customers because it's a vowel. So let's get the customers and we can see that that is going to return us a list a customers. So I think I'll store that as a local valuable type list. Just missed off my closing anchor bracket there. Right, I'll just import the list object. And that's now compiling and so I should be able to do customers dot. What you'll notice here is that we've defined customers as a list. Which is of course exactly what it is but this is a immutable list in Kotlin. Which means we shouldn't be able to add values to the list or change the values in the list. And yet, as you can see, we've got access to the add method. If you remember in Kotlin, the way that a immutable list are created…
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.