I am not able to understand and I couldn\'t find the meaning of out keyword in kotlin.
You can check example here:
List
>
Refer to thie manual of kotlin
The Kotlin
Listtype is an interface that provides read only operations like size, get and so on. Like in Java, it inherits fromCollectionand that in turn inherits fromIterable. Methods that change the list are added by theMutableListinterface. This pattern holds also forSetand/MutableSet MapV>/MutableMap
And this,
In Kotlin, there is a way to explain this sort of thing to the compiler. This is called declaration-site variance: we can annotate the type parameter T of Source to make sure that it is only returned (produced) from members of
Source, and never consumed. To do this we provide the out modifier:> abstract class Source{ > abstract fun nextT(): T } > > fun demo(strs: Source ) { > val objects: Source = strs // This is OK, since T is an out-parameter > // ... } The general rule is: when a type parameter
Tof a classCis declared out, it may occur only in out-position in the members ofC, but in returnCcan safely be a supertype ofC.In "clever words" they say that the class
Cis covariant in the parameterT, or thatTis a covariant type parameter. You can think of C as being a producer of T's, and NOT a consumer ofT's. The out modifier is called a variance annotation, and since it is provided at the type parameter declaration site, we talk about declaration-site variance. This is in contrast with Java's use-site variance where wildcards in the type usages make the types covariant.