Danial
Danial

Reputation: 622

kotlin class on any class

I'm trying to store class type as a member variable in my android application, so that I can go to that activity next. I am using Class of Any, but I don't know why it is not accepting type of any class, which means anything.

    val state : MutableLiveData<Pair<State,Class<Any>>>
            = MutableLiveData(Pair(State.Initial,MainActivity::class.java))

Can anyone help me resolving this issue ?

Upvotes: 0

Views: 87

Answers (1)

Sergio
Sergio

Reputation: 30755

Try to use out modifier for generic type:

val state : MutableLiveData<Pair<State, Class<out Any>>>
        = MutableLiveData(Pair(State.Initial, MainActivity::class.java))

out modifier is used in Kotlin to indicate covariance (similar to ? extends T in Java).

Upvotes: 3

Related Questions