https://kotlinlang.org logo
#announcements
Title
# announcements
a

Andrew Gazelka

07/10/2019, 1:07 PM
can someone explain this auto type? (when doing
flowOf(1, 1.0, 2, 2.0)
)… don’t understand the
&
e

elizarov

07/10/2019, 1:12 PM
&
here reads as
and
. The types here are comparable to any type that is
Double
and
Int
at the same time (such types don’t exist, but compiler does not check that) and extend
Number
.
m

Marc Knaup

07/10/2019, 1:24 PM
Why doesn't it just resolve to
Number
?
d

diesieben07

07/10/2019, 1:25 PM
Because
Comparable<Double & Int>
is more precise than
Number
m

Marc Knaup

07/10/2019, 1:42 PM
But
Double & Int
is impossible? A type cannot be both at once.
Comparable<Double | Int>
would make sense to me.
d

diesieben07

07/10/2019, 1:50 PM
It's a union type, it can be either double or int.
k

karelpeeters

07/10/2019, 1:51 PM
Think about actually using the interface: if I want to call
compareTo
I need to give sometime that is both an
Int
and a
Double
for it to work. Obviously that's impossible, but the type system doesn't know that.
m

Marc Knaup

07/10/2019, 1:59 PM
@diesieben07 my example is union. The initial one is intersection
d

diesieben07

07/10/2019, 1:59 PM
True. I need to think about this more 😄
m

Marc Knaup

07/10/2019, 2:03 PM
@karelpeeters as far as I understand the type system does know (otherwise type inference would never work), tots just that the compiler doesn't care. There was an article on intersection types in inference and why they're different from actual types but I can't find it anymore.
k

karelpeeters

07/10/2019, 2:04 PM
Okay, but that doesn't change what I said:
Int & Double
does make sense,
Int | Double
wouldn't.
m

Marc Knaup

07/10/2019, 2:11 PM
Ah, now I see it. I've always assumed that Java's
Number
is
Comparable
but it isn't. So the initial type basically reads
this is a Number which is Comparable but you can't actually use generic elements of Comparable because the possible type arguments are disjoint up to but excluding Any Number
(
out
may work as Any Number but Comparable has no type arguments in out position)
k

karelpeeters

07/10/2019, 2:12 PM
Not sure about "up to but including",
Any
doesn't work either.
Nothing
does simple smile But yeah, that what it means.
🙏 1
m

Marc Knaup

07/10/2019, 2:13 PM
Yeah it depends on the projection. I've just updated my message :)
h

Hullaballoonatic

07/11/2019, 6:11 AM
please give
&
syntax for type parameters instead of
where
syntax, JB!
e

elizarov

07/11/2019, 6:55 AM
Do you use it often? Just remember, that are so few ascii characters — each one is precious.