https://kotlinlang.org logo
#language-evolution
Title
# language-evolution
r

rrader

03/21/2020, 9:57 PM
Is it possible to add smart cast for such cases?
Copy code
data class EmployeeDetailedDTO(val firstName: String)

class EmployeesRepository {

    inline fun <reified T> findPage(isDeleted: Boolean = false): List<T> {
        return when(T::class) {
            EmployeeDetailedDTO::class -> listOf(EmployeeDetailedDTO("John")) as List<T>
            else -> TODO()
        }
    }
}
so, it will not be needed to add
as List<T>
1
m

marstran

03/25/2020, 10:09 AM
I wonder if contracts can be used to somehow achieve this in 1.4: https://blog.jetbrains.com/kotlin/2020/03/kotlin-1-4-m1-released#contracts-support
2 Views