Before discussing any more theory, it’s best to look at a simple generics example. The following program defines two classes. The first is the generic class Gen, and the second is GenDemo, which uses Gen.
The output produced by the program is shown here:
Let’s examine this program carefully. First, notice how Gen is declared by the following line:
Here, T is the name of a type parameter. This name is used as a placeholder ...