Marc Knaup
02/06/2019, 11:13 PMAny?
from the array but write only X?
and subtypes into it?
That ..
confuses me because it looks like a range 🤔
Oh and the out
thingy can be null
. The in
one not.dsavvinov
02/07/2019, 10:58 AMString
can be viewed as “Some type which can take values from String
to String?
, which is essentially `String..String?`“. If you’re curious, you can find more in this talk by Andrey Breslav: (caution: a lot of nitty-gritty details!)
- Platform arrays are a special case of platform types: T[]
is represented as Array<T!>..Array<out T>
to maintain compatibility with both Kotlin code and Java code
- Use-site variance adds even more complexity to this example. TL;DR: yes, you’re right, you can read Any?
from array and write subtypes of X?
.
If you’re into academic reading and type systems, I suggest you reading Ross Tate’s paper on mixed-site variance (http://www.cs.cornell.edu/~ross/publications/mixedsite/mixedsite-tate-fool13.pdf)Marc Knaup
02/07/2019, 11:01 AM