Why can't I set `foo` of `b: Base<*>` to `nu...
# getting-started
l
Why can't I set
foo
of
b: Base<*>
to
null
? I understand why it can't be set to any list but don't get why
null
shouldn't be allowed.
Copy code
abstract class Base<T> {
    // foo is nullable
    final var foo: MutableList<T>? = mutableListOf()
}

class Inherit : Base<String>()

val a = Inherit()
a.foo = null // works
a.foo = mutableListOf() // works

val b: Any = if (Random.nextBoolean()) a else Any()
if (b is Base<*>) {
    // error: 'Setter for 'foo' is removed by type projection'
    // I understand why it can't be set to any list but `null` should always be ok
    b.foo = null
}
d
Actually, it looks like a bug or new minor feature Please report it to kotl.in/issue
l