Java – JAXB uses the extension object factory to extend the generated code – explicit conversion, okay?
I have some JAXB - generated beans, which are hierarchical. For example, a bean has a list of other beans Now I want to extend some child elements and the parent element containing the extended child elements
My parentex implements some other interfaces iparent, which should return collection < ichild > My childex implements ichild When super Getchild() returns list < child >? I can return (collection < ichild >) super Getchild () or is there a better way?
>Child and parent are JAXB generated beans > childex and parentex are my own beans, which are used to map JAXB beans to a given interface Both beans override objectfactory > ichild and iparent, which are required interfaces for some other libraries
Editor: Eclipse doesn't even let my cast come from list < child > List < childex >, so I have to add some ugly intermediate wildcard cast (list < childex >) (list ) super getChild()
Solution
This should work:
return new ArrayList<IChild>( childExList );
Or (not beautiful but avoid wildcards):
return Arrays.asList( childExList.toArray(new IChild[]{}) );