can someone explain this auto type? (when doing `f...
# announcements
a
can someone explain this auto type? (when doing
flowOf(1, 1.0, 2, 2.0)
)… don’t understand the
&
e
&
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
Why doesn't it just resolve to
Number
?
d
Because
Comparable<Double & Int>
is more precise than
Number
m
But
Double & Int
is impossible? A type cannot be both at once.
Comparable<Double | Int>
would make sense to me.
d
It's a union type, it can be either double or int.
k
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
@diesieben07 my example is union. The initial one is intersection
d
True. I need to think about this more 😄
m
@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
Okay, but that doesn't change what I said:
Int & Double
does make sense,
Int | Double
wouldn't.
m
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
Not sure about "up to but including",
Any
doesn't work either.
Nothing
does simple smile But yeah, that what it means.
🙏 1
m
Yeah it depends on the projection. I've just updated my message :)
h
please give
&
syntax for type parameters instead of
where
syntax, JB!
e
Do you use it often? Just remember, that are so few ascii characters — each one is precious.