There is a way to declare a some list/array var an...
# announcements
k
There is a way to declare a some list/array var and say that item type is
T : X
(type T that implements/extends a type X)?
n
I don't follow why you would need this
a value doesn't decide whether T inherits from X
the value is just of type T, T has already decided whether it inherits from X
Unless you mean, that you don't care about what T is specifically? Like, you want to create an object of some type you don't care about, that extends X. That would be object expressions.
k
yes, its kinda of it
but I found a way to do what I need without using
T : X
but thanks anyway
just for explanation: I have two table table types with diferent headers and I created two models that represents each header with specific title and another generic model to extend/implements the first ones and I wish implement it in a way to force next models that will be create implement this generic model
So I did:
Copy code
lateinit var headers: List<Header>

headers = getHeadersFrom(platform)

private fun getHeadersFrom(platform: Platform): List<Header> {
    return when (platform) {
        Platform.ORGANIZZE -> {
            Organizze.Headers
        }
        Platform.MOBILLS -> {
            Mobills.Headers
        }
    }
}
Copy code
open class Header(open val text: String)
Copy code
object Organizze {
    val Headers = listOf(
        HeadersDict.DATE(),
        HeadersDict.DESCRIPTION(),
        HeadersDict.CATEGORY(),
        HeadersDict.VALUE(),
        HeadersDict.SITUATION()
    )

    sealed class HeadersDict(override val text: String) : Header(text) {
        class DATE(override val text: String = "Data") : HeadersDict(text)
        class DESCRIPTION(override val text: String = "Descrição") : HeadersDict(text)
        class CATEGORY(override val text: String = "Categoria") : HeadersDict(text)
        class VALUE(override val text: String = "Valor") : HeadersDict(text)
        class SITUATION( override val text: String = "Situação") : HeadersDict(text)
    }
}
Copy code
object Mobills {
    val Headers = listOf(
        HeadersDict.DATE(),
        HeadersDict.DESCRIPTION(),
        HeadersDict.VALUE(),
        HeadersDict.ACCOUNT(),
        HeadersDict.CATEGORY()
    )

    sealed class HeadersDict(override val text: String) : Header(text) {
        class DATE(override val text: String = "Data") : HeadersDict(text)
        class DESCRIPTION(override val text: String = "Descrição") : HeadersDict(text)
        class CATEGORY(override val text: String = "Categoria") : HeadersDict(text)
        class VALUE(override val text: String = "Valor") : HeadersDict(text)
        class ACCOUNT( override val text: String = "Conta") : HeadersDict(text)
    }
}
Copy code
enum class Platform(val id: Int, val text: String) {
    MOBILLS(1, "Mobills"),
    ORGANIZZE(2, "Organizze");
n
looks like you're ending up with an awful lot of globals
prob ok though if they're not mutable
k
they are not