I'm coding in kotlin, and i have a problem with the Arrays
I would make a function that return an Array of Car (for example), but that array is build by data from file
Exemple :
fun buildAllCar(data:string) : Array<Car> {
val array = arrayOfNulls<Location>(5) //In the real code, the size is retrieved by an other item
for(i in array.indices){
array[i] = buildACarByData(data); //Just so you could see a sample usage
}
return array.requireNoNulls()
}
Without the requireNoNulls() , the type of object returned is Array of Car? Use this method is the only way to get an Array of Car or there is a other way?
Thanks for your help
Array? AListwould seem to be more appropriate. (Arrays are needed for backward compatibility, but lists are more flexible and powerful and better for most things.)