I have the following program:
class MyGenClass{
public <T> void setAge(T ageParam){
Integer age = ageParam;
}
}
class Program{
public static void main(String args[]){
MyGenClass gnClass = new MyGenClass();
gnClass.<Integer>setAge(80);
}
}
In fact, i am passing the Integer
then why the ageParam
is not assigned to age
. And when i do:
class MyGenClass{
public <T> void setAge(T ageParam){
T age = ageParam;
}
}
Why the generic type variable is not assigned to the Integer
type variable age
in fact the generic type variable ageParam
is Integer
. Is this compulsory that the ageParam
must be assigned to the variable that is of type T
? Whats the scenario behind this?