Template Classes
Two main problems with Java approach:
- Non-object values, such as primitive types, cannot be stored in Java collections. (c.f. wrapper class, Integer)
- When a value is removed, it must be cast back to the appropriate type.
With templates, the C++ allows creation and manipulation of truly reusable, general purpose components with a minimum of difficulty but retention of type safety.
On the other hand, Java can easily maintain heterogeneous collection, that is, collections of values of various types.