So I have my code like this
var items = arrayOfNulls<String>(20)
Clearly I mentioned <String>, not <String?> . In the next code, I add bunch of string values to my items variable, but when I convert my items variable to list of string, I got error mismatch type that my items variable is detected as <String?>. Here is my conversion code.
val texts: List<String> = items.toList()
I can change my texts declaration into List<String?> to avoid the error, but that's not what I wanted. I want my texts variable data type is List<String>. Turns out the root caused is I expected null value during my items declaration and it changed the data type from <String> to <String?>. But how to declare an ampty array without expecting null?