which algorithms are written in terms of types to-be-specified-later that are then instantiated when needed for specific types provided as parameters. ~Wikipedia
= numberList -> Won't work Why? Take the numberList and add a double numberList.add(5.0) This does not correspond to the integer list and does not assure type safety
variance on a type parameter They are In and Out. When provided at the type parameter declaration site, where the generic type is declared, they are referred to as declaration-site variance. Else,when the annotation is not placed where the type is declared, but where the type is used.It’s use-site variance.
type than originally specified. The specified type or its supertype. Example: //List is Invariant val numberList:List<Number> = mutableListOf() //val genericList: List<Int> = numberList → Won’t Compile
can’t call those methods that consume the type parameter val arrayOfSomethingElse: Array<out Food> = arrayOf() // arrayOfSomethingElse[0] = Fish() --> Won't Compile arrayOfSomething[0] Example:
argument, but need to use them in a safe way. The safe way here is to define such a projection of the generic type, that every concrete instantiation of that generic type would be a subtype of that projection. ~From Docs Star Projection:
usages are only done at compile time. At runtime, the instances of generic types do not hold any information about their actual type arguments. Enforcing type constraints only at compile time and discarding the element type information at runtime. The type information is said to be erased.