Delegated properties are one of the best features of Kotlin language. We have already seen observable and vetoable delegates. In this recipe, we will learn how to create our own custom delegate. As a demo example, we will create a delegate property that can only be initialized once; if done again, it should throw an exception. So let's dive into it and see how we can achieve it.
Writing your own delegates
Getting ready
We will be using IntelliJ IDEA for coding purposes. You can use any IDE capable of executing Kotlin code.
How to do it…
Now, let's dive...