https://kotlinlang.org logo
#codereview
Title
# codereview
c

csturtevant

12/30/2019, 10:55 PM
Hi there, can anyone help me resolve this Intellij warning?
Type mismatch: inferred type is (Mutable)List<Task!>? but MutableList<Task> was expected
I’m writing a Kotlin class implementing this interface method:
Copy code
List<Task> getTasksReport(@NonNull String filter);
The Kotlin implementation is:
Copy code
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?:
Copy code
override fun getTasksReport(filter: String): MutableList<Task> {
        val response = todoistRestClient.getTasks(TODAY_FILTER)
        val tasks = response.body
        println(tasks)
        return tasks as MutableList<Task>
    }
m

Matteo Mirk

12/31/2019, 7:58 AM
the warning is caused by the compiler not being able to determine the nullability of Java types, so I guess casting is the only option
3 Views