Appendix
Appendix A: Comparison to C++ templates
The syntax for generic classes bears a superficial similarity to the template facility in C++. However, there are substantial differences between the two. For example, a generic type in Java language cannot take a primitive type as a type parameter -- only a reference type. This means that you can define a List<Integer>, but not a List<int>. (However, autoboxing can help make a List<Integer> behave like a List of int.)
C++ templates are effectively macros; when you use a C++ template, the compiler expands the template using the provided type parameters. The C++ code generated for List<A> differs from the code generated for List<B>, because A and B might have different operator overloading or inlined methods. And in C++, List<A> and List<B> are actually two different classes.
Generic Java classes are implemented quite differently. Objects of type ArrayList<Integer> and ArrayList<String> share the same class, and only one ArrayList class exists. The compiler enforces type constraints, and the runtime has no information about the type parameters of a generic type. This is implemented through erasure
, explained in The gory details
.

