Is that a mandatory stuff that you should make use of Generics ? I don't think so !!! :-)
This is a kind of design problem. Try to make use of design pattern.
If your problem, "Factory Design Pattern" will do the thing.
Factory design pattern will create Sub classes of type you need.
For more info on it, have a look at here.
http://en.wikipedia.org/wi
http://www.dofactory.com/P
http://www.dofactory.com/P
Main Topics
Browse All Topics





by: JathrekPosted on 2007-04-26 at 15:45:28ID: 18985728
The thing is, you're trying to use generics at runtime, which is not possible, as generics are being handled at compile time (it's just some kind of type checking that allows developers to directly use the good typing instead of having to cast Object into some other classes - it helps by allowing him to detect casting errors at development time, not after compilation - and once the checks are finished, the generics informations is "forgotten" in the compiled code).
So it's actually not possible to do something like "new K(...)", where K would be a generic keyword.
In fact, I advise you to try to do it some other way...
Maybe it would be possible to do it by simply not using generics and giving a CompositeGameObject factory as a parameter of the constructor of GameObjectFactory? Or maybe you could just give a Class object and instantiate the subclasses of CompositeGameObject using reflection (calling newInstance() on the Class object).
It's not really the answer you expected, but if you want more informations, just ask.