mardi 17 juillet 2018

Usecases for this covariant class?

I've encountered this class

sealed class Test<out T> {
}

fun <T, R : T> Test<T>.abc(fn: (Int) -> Test<R>) {
    fn(10)
}

In a reddit post asking why it couldn't be written like this:

sealed class Test<out T> {

    fun abc(fn: (Int) -> Test<T>) {
        fn(10)
    }

}

I have since wondered where such a sealed class would be useful but couldn't think of anything.

What are example applications of the above Test class design?

Aucun commentaire:

Enregistrer un commentaire