Does it mean that I can read `Any?` from the array...
# random
m
Does it mean that I can read
Any?
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.
🤯 1
d
Well, that’s… complicated 😉 - Platform types are indeed represented as a range of types internally. Indeed, platform
String
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:

https://www.youtube.com/watch?v=2IhT8HACc2E

(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)
👍 2
m
Thank you Dmitry, that's helpful! I do love details indeed and will check it out 🙂