Tutorial by Examples

Declaration-site variance can be thought of as declaration of use-site variance once and for all the use-sites. class Consumer<in T> { fun consume(t: T) { ... } } fun charSequencesConsumer() : Consumer<CharSequence>() = ... val stringConsumer : Consumer<String> = cha...
Use-site variance is similar to Java wildcards: Out-projection: val takeList : MutableList<out SomeType> = ... // Java: List<? extends SomeType> val takenValue : SomeType = takeList[0] // OK, since upper bound is SomeType takeList.add(takenValue) // Error, lower bound for...

Page 1 of 1