Why does this not work?
class MyClass<GenericClass> {
GenericClass myInstance;
MyClass() {
myInstance = new GenericClass();
}
}
I get a "cannot instantiate" COMPILE time error message on the 'new'. Even if I make sure that there is a parameterless constructor.
Follow up: is there a preferred way to address this? Or am I forced to do this (assuming I have added the setMyInstance() method to MyClass<>
class Other {
...
...
}
MyClass<Other> mine = new MyClass<Other>();
mine.setMyInstance(new Other());
Which is not great because I am forced to reveal the implementation of MyClass outside of it.
What's the better way to handle it?