Junior — Middle
What reasons allow the use of the TODO directive with any data type or structure?
sobes.tech AI
Answer from AI
In Kotlin, the directive TODO() is a function that always throws a NotImplementedError exception. It is declared with a return type of Nothing, which means that the function never returns a value and terminates execution.
Thanks to the Nothing type, TODO() can be used anywhere a value of any type or structure is expected. This allows temporarily stubbing out implementation without worrying about the specific return type. For example:
fun getUser(): User = TODO("Implement user retrieval")
val number: Int = TODO()
val list: List<String> = TODO()
Thus, TODO() serves as a convenient marker for unfinished code, allowing the program to compile and indicating places that require further development, regardless of the data type.