Now a days i am looking at Generics. Which is very interesting.
But i have a confusion .......
[code=java]
class GenericClass<T> {
T obj;
GenericClass(T t){
this.obj = t;
}
}
class MyMainClass{
MyMainClass(){
GenericClass<Nu mber> gc = new GenericClass<In teger>();
}
}[/code]
Now my question is that, why it shows me error .....Compiler says that incompatible types.
But what i think as Integer extends Number .... why it's not valid please explain me!
But i have a confusion .......
[code=java]
class GenericClass<T> {
T obj;
GenericClass(T t){
this.obj = t;
}
}
class MyMainClass{
MyMainClass(){
GenericClass<Nu mber> gc = new GenericClass<In teger>();
}
}[/code]
Now my question is that, why it shows me error .....Compiler says that incompatible types.
But what i think as Integer extends Number .... why it's not valid please explain me!
Comment