Hi Sarwar,
class GenTest<T super Number> {
T num;
public T checkNumber(T n) {
return n;
}
}
There is compiler error, because it is senseless, we are not
allowed to write "class GenTest<T super Number>{}" or so.
Let us see why?
You know compiler does type erasure so the type erasure of your
class definition would have been become(if compiler provided that),
You can see that the ultimate type erasure would be Object,
you couldn'y have called the instance methods of the Number
where as <T extends Number> you can call the instance
methods of the Number because the type erasure is <Number>
(the left most bound).
In the "super" case when after the type erasure the type becomes
Object, the same trouble of casting to Number, when you require to
call Number specific method although you could have called the
Object instance method simply, but what could have come in your
hand. Nothing!!!
Other case, you have not been able to instantiate the class like:
GenTest<Double> d1 = new GenTest<Double>(); or
GenTest<Integer> d2 = new GenTest<Double>();
That is because it would be class GenTest<T super Number> {}
What is its need if only you are allowed to do :
GenTest<Number> d1 = new GenTest<Number>(); and
GenTest<Object> d2 = new GenTest<Object>();
That is why we are not provided with <T super Number> like senseless things.
Hope you got the above verbose details,
Thanks and Regards,
cmbhatt
[ April 06, 2007: Message edited by: Chandra Bhatt ]