Introduction to Generics

The concept of generics produces parameterized types, so you can create components that work across multiple types.

The term “generic” means “pertaining or appropriate to large groups of classes.” The original intent of generics in programming languages was to provide the programmer maximum expressiveness when writing classes or functions, by loosening type constraints on those classes or functions.

One of the most compelling initial motivations for generics is to create collection classes, which you’ve seen in the Lists, Sets and Maps used throughout this book. A collection is an object that holds other objects. Many programs require you to hold a group of objects while you use them, so collections are one of the most reusable of class libraries.

End of sample. See AtomicKotlin.com for full early-access book.



Previous          Next

©2018 Mindview LLC. All Rights Reserved.