swaraj gupta wrote: What my doubt is: what " <T extends Animal>" has to with the instance creating statements on line no. 5 and 6. Problem is with the instantiation of the class with Integer parameter-type or with the instance variable of type T that could be of type Animal or its subtype? m confused..
Its indicating to the compiler the value for the Type T- So that the compiler can replace T with what ever type you specify. And <T extends Animal> adds a constraint that T has to be a subclass of Animal. I would say- you can brush through the generics concepts again, so that this becomes a bit more clearer.
swaraj gupta wrote: Will you please tell me what conclusion have you drawn from: AnimalHolder<T extends Animal> { } only.
In your class declaration you say- T extends Animal. So what ever type specified while creating the instance of AnimalHolder should be subclass of Animal.
swaraj gupta wrote: And if am not using T as parameter-type of constructor of class AnimalHolder then what's the problem here.
If you are not specifying the Type(T) parameter- Then you arent using generics there and in that case T becomes an Object.