https://kotlinlang.org logo
Title
r

Ruckus

05/11/2018, 8:53 PM
Why are
any
and
all
defined on
Array<out T>
instead of
Array<T>
?
k

karelpeeters

05/11/2018, 9:27 PM
I've been trying for about 10 minutes now but I can't find any combination where it makes any difference.
r

Ruckus

05/11/2018, 10:04 PM
What?
k

karelpeeters

05/11/2018, 10:06 PM
I've tried to define my own version of
any
that isn't defined on
Array<out T>
but on
Array<T>
, but couldn't find a case where that didn't work exactly as the real one.
r

Ruckus

05/11/2018, 10:07 PM
I expect it to work the same. My issue is that I have an
Array<T>
and can't use
any
because it's defined on
Array<out T>
i

ilya.gorbunov

05/12/2018, 4:30 AM
Array<T>
is a subtype of
Array<out T>
, so any extensions for the latter are available for the former.
r

Ruckus

05/12/2018, 4:50 AM
Hmm, that makes sense. I must have been doing something else wrong. I'll have to check when I get back to a computer.
k

karelpeeters

05/12/2018, 6:25 AM
@ilya-gh Why is it defined on
out
then if its the same either way?
r

Ruckus

05/12/2018, 3:02 PM
@karelpeeters Wrong Ilya. You meant @ilya.gorbunov.
k

karelpeeters

05/12/2018, 3:51 PM
Dammit not again. Thanks!
i

ilya.gorbunov

05/12/2018, 10:19 PM
We use out variance to emphasize that an out-projected array is enough for the particular operation.
k

karelpeeters

05/12/2018, 10:22 PM
And are there cases where it actually does something? Ie. does it allow more programs to compile?
i

ilya.gorbunov

05/12/2018, 10:30 PM
It can make a difference in cases when there are more than one
T
position in a function signature.