r

    rrader

    2 years ago
    Is it possible to add smart cast for such cases?
    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>
    m

    marstran

    2 years ago
    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