Before you can do anything on a Object, you have to cast it into the actual type supporting the operation. But, what type would that be? The vector code doesn't know the type, so it's your client code that has to know what's going on.Schol-R-LEA, in the thread "BASIC for OS-Development?", wrote on 2003-08-26 19:45:
Templates as they exist in C++ are a workaround due to the lack of a singly rooted object hierarchy, or such as my understanding. In a language where all variables are objects off of a single root, they are completely unnecessary; you'd simply declare the method as class Object (or whatever the root class is) and apply to whatever classes you wish.
And what happens if you add polimorphy? If you have a vector of Object, and cast them to BaseClass, you have... well, you have objects of type BaseClass. Since Java doesn't have pointers, you have just sheared off any information on derived type. (IIRC.)
With a template, the type held in a vector is still known, to both client and vector code; yet still, the vector code can handle the type as being generic. If the type is a pointer type, you even preserve information on derived type.
Casting Java Object to whatever the container contents actually are also involves a greater risk of run-time errors: The Java container is not type-safe. C++ templates, on the other hand, are instantiated at compile time, including type checking. If the objects inserted into vector<T> don't support the operation called on them, your compiler will complain (instead of your code failing at run-time).
And templates are not only about containers. In the STL, you have algorithms that function on generic containers, and containers you can use generic algorithms on. When you implement a new algorithm, you have to implement it only once to have it work with many different container types - even those you don't even know about - without sacrificing run-time efficiency.
That's for starters. I'm open for questions, and if I can't answer them, I'll forward them to my co-worker, who really should know since he helped setting the standard.