My first experience with generics was back in 2004, when they were first introduced in the Java programming language. I can still remember picking up my copy of The Java Programming Language, Fourth Edition, which covered Java 5, and reading about Java's implementation of generics. Since then, I have used generics in a number of projects, not only in Java but in other languages as well. If you are familiar with generics in other languages, such as Java, the syntax that Swift uses will be familiar to you. Generics allow us to write very flexible and reusable code; however, just as with subscripts, we need to make sure that we use them properly and do not overuse them.
In this chapter, we will cover the following topics:
An introduction to generics
Creating and using generic functions
Creating and using generic classes
Using associated types with protocols