Generics, WTF?
Generics are complicated, and that ties into some esoteric-looking Kotlin syntax that we will explore much later in the book:
- When you see the 
outkeyword, such as inclass Something<out T>, that is Kotlin’s approach for declaring “covariance”, stipulating that an instance ofSomethingis allowed to produceTobjects (e.g., return them from functions) but not consume them (e.g., accept them as parameters) - When you see the 
inkeyword, such as inclass Something<in T>, that is Kotlin’s approach for declaring “contravariance”, stipulating that an instance ofSomethingis allowed to consumeTobjects but not produce them - When you see 
<reified T>… well, that is difficult to explain 
Prev Table of Contents Next
This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.