DEV Community

Discussion on: Is there vararg-like generics in Java?

Collapse
 
siy profile image
Sergiy Yevtushenko

Well, the real guide would be a thick book like C++ Templates: The Complete Guide. But in brief, this is a technique, which allows the compiler to generate classes at compile time using the description of a generic class as a template. With this approach the compiler creates a new class for every type argument passed to template. For example, if your Java code uses List<String> and List<Integer>, both of these classes are actually the same instance of class List with type of contained element erased at compile time. In C++ same types will result in two different classes, where each class has its own set of methods and possibly different internal layout of the class. There are much more details and both approaches are not so simple, but overall high level picture looks as described above. By the way, if you're really interested in gaining more knowledge about C++ templates, the book mentioned above is one of the best among those dedicated to the topic.