This will be a short lesson, just wanted to show you guys that as we said in the previous post, you can’t create an array with only giving the array size to the constructor, otherwise it will be a NULL array which Kotlin hates.
As always Kotlin gives you the power to have null only if you explicitly asked for it.
So to create a Null Array in Kotlin you have to do it like this.
val nullableInts = arrayOfNulls<Int>(5) for (i in nullableInts) { println(i) }
We will get 5 nulls as the output.
one last note is that when you try to access the functions of the array, you will see that the compiler blocks most of the functions ‘the ones that will cause problems with nulls’.
That’s it for this lesson, I will be around if you have questions, see you later 😀
very good tutorial mr 2ni, looking forward for your next articles