I
IveCal
Hi all,
Please help. I cant understand this piece of code regarding generics.
See the code below:
class Gen<T>{
T ob;
Gen(){
ob = new T(); // <---- POINT OF CONFUSION
}
}
My question is: why is it illegal to instantiate ob = new T();?
I thought T is replaced with the appropriate type (through the process
called erasure) during COMPILE time so that it will look AS IF IT WERE
WRITTEN like this:
// Assume argument type is String
class Gen{
java.lang.String ob;
Gen(){
ob = new java.lang.String(); // I assumed it look like this.
}
}
Please help! I'm stuck!
Regards,
Ive
Please help. I cant understand this piece of code regarding generics.
See the code below:
class Gen<T>{
T ob;
Gen(){
ob = new T(); // <---- POINT OF CONFUSION
}
}
My question is: why is it illegal to instantiate ob = new T();?
I thought T is replaced with the appropriate type (through the process
called erasure) during COMPILE time so that it will look AS IF IT WERE
WRITTEN like this:
// Assume argument type is String
class Gen{
java.lang.String ob;
Gen(){
ob = new java.lang.String(); // I assumed it look like this.
}
}
Please help! I'm stuck!
Regards,
Ive