WillieLWZ wrote:
> wrote:
>
>>You can avoid it by including an abstract method in the superclass that
>>matches each method in the subclass. Then through polymorphism the
>>correct implementation will be used based on the run-time type of the
>>parameter.
>
>
> Thanks for the suggestion, however let's assume that the superclass
> (ClassA) is in a library (say java.lang) and so cannot be modified and
> that SubClassA is not to be exposed. (i.e. private class)
>
This seems like a typical problem encountered hen inheritance is used
instead of delegation.
What would your design look like if you encapsulated the java.lang base
class, rather than derived from it?
For certain, the instanceof check would disappear.
Andrew