Sam Stone
08/03/2023, 8:44 PMfoo
without me specifying? (I need to include <Int>
in val foo: Sealed1.Sub1<Int>
even though they all have the same type) I think it should be able to, so it is in #language-evolution (not in #language-proposals because there may be a good reason why it can’t).
val foo: Sealed1.Sub1
get() = Sealed1.Sub1(
Sealed2.Sub2(123)
)
sealed class Sealed1<T>(
open val value: Sealed2<T>
) {
data class Sub1<T>(
override val value: Sealed2<T>,
) : Sealed1<T>(value)
}
sealed class Sealed2<T>(value: T) {
data class Sub2(val myValue: Int): Sealed2<Int>(myValue)
}
Youssef Shoaib [MOD]
08/03/2023, 9:55 PMval foo: Sealed1.Sub1<_>
should do the trick. The reason is that unqualified (a.k.a raw) generics are not allowed in Kotlin because they are a bit ambiguous. The _ tells the compiler to infer the type param for Sub1.
Btw, I believe you can remove the type specification altogether and just do val foo get() =
Sam Stone
08/04/2023, 12:15 AM<_>
) require? I don’t recognize it.Sam Stone
08/04/2023, 12:15 AM*
?Sam Stone
08/04/2023, 12:17 AMfoo.value.myValue + 1
is an error).ephemient
08/04/2023, 12:53 AM<_>
is not an error, and means something different than <*>
ephemient
08/04/2023, 12:55 AMYoussef Shoaib [MOD]
08/04/2023, 9:03 AM