Generics : Bounded Types
In generics, the type parameters could be replaced by any class type. But in some scenarios, we would like to set a boundary on the class types. Lets consider one such scenario. Suppose we want to concatenate a string to the object. Lets see the generic class defined below : public class BoundedTypeClass< T > { T obj ; BoundedTypeClass ( T o) { obj = o ; } T getObj () { return obj ; } public void concate () { obj .concat( "Done" ) ; } public void show () { System. out .println( "The type of obj is : " + obj .getClass().getName()) ; } } Now concat() is a method only available to Strings. This results into a compilation error : cannot find concat() for type T. Another scenarios where errors can occur are when we pass Strings in a method that computes the average of integers. For this example, to only accept strings, we need to bind the type. i.e. we need to extend T with a supercl