Thanks Jim, that I didn't know. That's two things I have learned today... I can take tomorrow off
I am trying to think of a situation where returning a subtype in an overridden method would be useful - mostly overridden classes will be called polymorphically so the client would normally not be aware of the more specific subtype.
Can you think of an example of where this may be useful to aid my understanding of it's use?
Thanks
Originally posted by Jim Yingst:
Also:
[Rick]: The getChild method works OK so I am not understanding why the addChild is no good.
When overriding or implementing a method, you can always (as of JDK 5) provide a more specific return type than the original method declaration did. That is, if the original return type was a reference type, the overriding return type may be a subclass or subinterface of the original. This is true regardless of whether the class is generic or not.