So, we are in the third chapter of, Functional Kotlin. In this chapter, we are going to discuss immutability. Immutability is probably the most important aspect of functional programming; actually, not only in functional programming, but OOP also gives some room to nurture immutability with immutable objects. So, why is it so important? What does it mean? How can we implement immutability in Kotlin? Let's answer these questions in this chapter.
The following are the points we are going to cover in this chapter:
- What is immutability?
- The advantages of immutability
- How to implement immutability in Kotlin?
- Immutability in variables
- val versus var
- val and const val—are they truly immutable?
- Compiler optimization
- Immutable collections
- The disadvantages of immutability