Got a little bit of a left-field question here, so...
# announcements
d
Got a little bit of a left-field question here, so bear with me... For type projections, you can put a variance annotation on a type argument in a declaration, like so:
Copy code
// 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_:
Copy code
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:
Copy code
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?