interface Source<out T> { fun nextT(): T...
# announcements
i
interface Source<out T> { fun nextT(): T }
s
have you read the docs on variance?
yeah
I don't understand why there're two concepts called " Consumers." and "Producers,"
it doesn't make sense to me
t
as I understand, it is a solution in Kotlin to solve generics issue in Java although Java has its own solution
i
<? extends E> which means ? is a subclass of E
<? super E> which means ? is a superclass of E
this is simple, but the annotate <in E> and <out E> are not easy to understand
s
I think it's easier. If E is coming out of the class (ie return types only), it can be an out type. If it's coming into the class (ie parameters) its an in type
i
but they're related with the type inheritance
now return or pass in
not
s
They are related. I think you should read the section "Declaration-site variance" in the above link. The names in and out are chosen to reflect what I said above.
m
It's more about simplifying the implications of defining a generic as
extends
or
super
. When writing in Java, unless you're very familiar with typing constraints, and what it means to allow variance of types, you REALLY have to think/read about when to use
extends
vs
super
. Kotlin is trying to make it easier as one can easily determine if the generic is being used as an
in
or an
out
by reading the definition class, and can use the appropriate modifier. Make sense?
Side note: You can edit your most recent message using up-arrow. Can also edit older ones from more actions menu for a message.