Dave Leeds
01/06/2018, 3:18 AM// Just for demonstration purposes - in real life you'd just use a non-mutable list, of course.
val list: MutableList<out Number> = mutableListOf(1, 2, 3)
You cannot, of course, put a variance annotation on the type argument of a _function call_:
val list: MutableList<Number> = mutableListOf<out Number>(1, 2, 3)
If you do this, you'll get a compiler error message that says:
Projections are not allowed on type arguments of functions and properties
That makes sense to me, except for the and properties
part. Is there ever such a thing as a type argument for property access? It's not talking about the property's type declaration, of course, because you can do this:
class Wrapper {
val list: MutableList<out Number> = mutableListOf(1, 2, 3)
}
So, the error message got me wondering whether I'm missing a concept here, or whether the error message is suggesting something that doesn't actually exist anyway. Thoughts?