Mateusz Konieczny
02/21/2023, 7:26 PMSurface
is subset of Surface?
so it will be expanded to it.
If unusual or should not happen I will try to make a minimal reproducible example out of https://github.com/streetcomplete/StreetComplete/pull/4642#pullrequestreview-1304594775fun Surface.asItem(): DisplayItem<Surface> = Item(this, iconResId, titleResId)
and
fun Surface.asItemWithFakeNullPossibility(): DisplayItem<Surface?> = Item(this, iconResId, titleResId)
but I suspect there is a better way to handle this...Wout Werkman
02/21/2023, 7:29 PMDisplayItem
is out
, then this is expected. I think you want to add out
Mateusz Konieczny
02/21/2023, 7:30 PMout
is doingmkrussel
02/21/2023, 7:31 PMSurface
is a subtype of Surface?
but that doesn't make DisplayItem<Surface>
a subtype of DisplayItem<Surface?>
. The subtyping of the generic types are based on the variance.
A good explanation.
https://typealias.com/guides/illustrated-guide-covariance-contravariance/Mateusz Konieczny
02/21/2023, 7:32 PMbut that doesn't makeI see that I need to learn more, I was expecting exact opposite (and got confused what is going on)a subtype ofDisplayItem<Surface>
DisplayItem<Surface?>
out
than official docs - please let me know!mkrussel
02/21/2023, 7:34 PMephemient
02/21/2023, 7:34 PMProducer<T>
is a subtype of Producer<T?>
Consumer<T?>
is a subtype of Consumer<T>
mkrussel
02/21/2023, 7:34 PMout
and in
keywords change the variance of the generics which changes the subtyping rules.ephemient
02/21/2023, 7:34 PMin
and out
because that's where it goesin T
, a producer gives out T
CLOVIS
02/21/2023, 9:13 PMList<Int>
is a List<Number>
), but this is unsafe if the list can be modifiedephemient
02/21/2023, 9:26 PM