csturtevant
12/30/2019, 10:55 PMType mismatch: inferred type is (Mutable)List<Task!>? but MutableList<Task> was expected
I’m writing a Kotlin class implementing this interface method:
List<Task> getTasksReport(@NonNull String filter);
The Kotlin implementation is:
override fun getTasksReport(filter: String): MutableList<Task> {
val response = todoistRestClient.getTasks(TODAY_FILTER)
val tasks = response.body
println(tasks)
return tasks
}
Would changing the Kotlin by adding the cast to the return to the following be the best implementation?:
override fun getTasksReport(filter: String): MutableList<Task> {
val response = todoistRestClient.getTasks(TODAY_FILTER)
val tasks = response.body
println(tasks)
return tasks as MutableList<Task>
}
Matteo Mirk
12/31/2019, 7:58 AM