Here is my question.
class Gen<T> {
T ob;
Gen() {
ob = new T(); // Illegal!!!
}
}
Why is it illegal? Could you please explain it.
genericsjava
Here is my question.
class Gen<T> {
T ob;
Gen() {
ob = new T(); // Illegal!!!
}
}
Why is it illegal? Could you please explain it.
Best Answer
This is impossible because of the following 2 reasons.
An answer may be to take a T factory in the constructor. Then Gen can request new Ts to its heart content.