Originally posted by Prosenjit Banerjee:
Then what if I want to add various types of objects (say, Strings, Integers, Panels) to the same vector?
Instead of Integer use a common superclass between the objects you want to add. Since
String, Integer and Panel have no other common superclass than Object, use:
Ofcourse, since Object is the superclass of all classes, this won't provide much type-safety...
Another example: Suppose you could add different kinds of numbers (integers, longs, doubles, ...). Then you could use Number as the parametric type, since Number is a common superclass of Integer, Long, Double etc.