I’ve got some JAXB generated beans which are in an hierarchical structure, e.g. one bean holds a list of other beans. Now I want to extend some child element and also the parent element holding the extended children.
My ParentEx implements some other interface IParent which is expected to return an Collection<IChild>. My ChildEx implements IChild. Can I return a (Collection<IChild>)super.getChild() when super.getChild() returns List<Child>? Or is there a nicer way of doing this?
ChildandParentare JAXB generated beansChildExandParentExare my own beans for mapping the JAXB beans to the given interfaces. Both beans override theObjectFactoryIChildandIParentare the interfaces needed from some other library
Edit: Eclipse doesn’t even let my cast from List<Child> to List<ChildEx> so I have to add some ugly intermediary wildcard cast (List<ChildEx>)(List<?>)super.getChild()
This should work:
or (not pretty but avoids wildcard cast):