- define an abstract parent class for your objects, (called PARENT here)
- with an abstract method that returns an object of its type, (called CREATE here) and then
- define the class that's going to generate your objects (called FACTORY here),
- with a method that looks something like:
As well, this actually throws an unchecked casting warning, so it probably needs a little tweaking. But everything else seems to upgrade the issues from a class cast warning (that you know of course won't happen, since C extend PARENT, and PARENT is abstract, and has abstract method CREATE that returns an object of class C)--from a class cast warning to a full-blown compiler error with the generics, so...

No comments:
Post a Comment