JP Sugarbroad
05/02/2025, 9:53 PMopen class Super
class Container<T: Super>
fun test(thing: Any) {
if (thing is Container<*>) {
val thing2 = thing as Container<Super>
}
}
But this does not?
open class Super
class Container<T: Super>
fun test(thing: Any) {
if (thing is Container<out Super>) {
val thing2 = thing as Container<Super>
}
}
Shouldn't *
be equivalent to out Super
in this case?loke
05/03/2025, 7:38 AMis
on an erased type.loke
05/03/2025, 7:40 AMContainer
.JP Sugarbroad
05/05/2025, 12:01 PMSam
05/06/2025, 7:43 AMfun main() {
test(mutableListOf<String>())
}
fun test(list: Any) {
if (list is MutableList<out Any?>) {
val list2 = list as MutableList<Any?>
list2.add(null)
}
}
Definitely feels like there's a warning missing here.JP Sugarbroad
05/06/2025, 5:24 PMJP Sugarbroad
05/06/2025, 5:24 PMSam
05/07/2025, 8:52 AMSam
05/07/2025, 8:53 AMJP Sugarbroad
05/07/2025, 6:26 PMJP Sugarbroad
05/08/2025, 8:54 PMSam
05/09/2025, 5:32 AMMutableList
in the description rather than just List
? A List<T>
is always a List<out T>
so I suspect it wouldn't exhibit the bug.JP Sugarbroad
05/09/2025, 2:55 PMJP Sugarbroad
05/09/2025, 2:56 PM