Mansukhdeep Thind wrote:So if we assume T to be, say, Integer type, then what that means is that whenever we create an object of Foo<Integer> type, it will be mutually comparable with <Number> object and <Object> object. Is that correct Winston?
No. It will depend entirely on how the type you substitute for
T is defined, and
Integer implements
Comparable<Integer>. The point is that it will STILL work if Integer had been defined as
Comparable<Number>, and that's what you're trying to achieve with generics:
maximum flexibility.
Remember: you have no idea what might be substituted for
T, so when adding restrictions, you want to make them as inclusive as possible.
Winston