spragg
12/06/2017, 2:45 AMkevin.cianfarini
12/06/2017, 3:52 AMkevin.cianfarini
12/06/2017, 4:18 AMkevin.cianfarini
12/06/2017, 4:18 AMspragg
12/06/2017, 5:09 AMout
. It felt backwards the first time I used it too. If you are passing in the variable then you need to use out
.spragg
12/06/2017, 5:09 AMspragg
12/06/2017, 5:11 AMAndreas Sinz
12/06/2017, 8:31 AMV
as out
, kotlin complains about Type parameter V is declared as 'out' but occurs in 'in' position in type V
spragg
12/06/2017, 8:36 AMin
spragg
12/06/2017, 8:39 AMval ref: Map<String, Class<out Fragment>> = mapOf()
which is what confused me.spragg
12/06/2017, 8:41 AMkevin.cianfarini
12/06/2017, 6:03 PMV : BaseMVPView
kevin.cianfarini
12/06/2017, 6:03 PMin
do anything to achieve contravariance?kevin.cianfarini
12/06/2017, 6:04 PMkevin.cianfarini
12/06/2017, 6:05 PMAndreas Sinz
12/06/2017, 8:27 PMin
kevin.cianfarini
12/06/2017, 8:28 PMkevin.cianfarini
12/06/2017, 8:28 PMAndreas Sinz
12/06/2017, 8:32 PMT: BaseMVPView
limits the available type arguments. passing an Int
into a method foo(n: Number)
is always possible, because kotlin knows that Int
is a subtype of Number
. in
is useful when casting a class from Comparable<Number>
into Comparable<Int>
Andreas Sinz
12/06/2017, 8:33 PMout
allows you to cast List<Int>
to List<Number>
kevin.cianfarini
12/06/2017, 8:34 PM<? extends Animal>
kevin.cianfarini
12/06/2017, 8:34 PMkevin.cianfarini
12/06/2017, 8:34 PMkevin.cianfarini
12/06/2017, 8:34 PM<T : BaseMVPView>
kevin.cianfarini
12/06/2017, 8:35 PMspragg
12/06/2017, 8:36 PMkevin.cianfarini
12/06/2017, 8:38 PM<? extends Animal>
effectively not the same in kotlin as <T : Animal>
?Andreas Sinz
12/06/2017, 8:40 PM<T: Animal>
is neither covariance nor contravariance. It just limits the Types that T
can bespragg
12/06/2017, 8:41 PM<? extends Animal>
is the same as <out Animal>'
<? super Animal>
is the same as <in Animal>
Andreas Sinz
12/06/2017, 8:42 PMin
and out
are class-level co-/contra-variance, e.g. in
allows you to cast Compare<Animal>
to Compare<Dog>
. With <T: Animal>
does not allow you to cast a class into Comparable<Animal>
into Comparable<Dog>
kevin.cianfarini
12/06/2017, 8:42 PM<? extends Animal>
both limits the types that can be used and also achieves covariance?Andreas Sinz
12/06/2017, 8:55 PM