January 2018
Intermediate to advanced
434 pages
14h 1m
English
Generic types in Java are invariant, which means List<String> is not a subtype of List<Object>. Java has this so that we are not able to add, say, a Float to a List that contains String and has the type as Object. In Kotlin, we have a better solution where we use the wildcard argument as ? extends E, which denotes that the method accepts a subtype of E or collection of E and not just E itself. This gives us the power to read from a collection of E but not write to it, as we do not know what items are accepted. This makes Kotlin covariant.
Read now
Unlock full access