"Scott Bates" <sa*****@slocrusade.com> wrote in message
news:70**************************@posting.google.c om...
I am attempting to create a JAXB Object that returns the
CollectionType as a List. In my schema file, I used the following:
<jxb:globalBindings>
collectionType="java.util.Vector"
</jxb:globalBindings>
This changed the initialization in the impl stub from the following:
protected com.sun.xml.bind.util.ListImpl _MyList = new
com.sun.xml.bind.util.ListImpl(new java.util.ArrayList());
to:
protected com.sun.xml.bind.util.ListImpl _MyList = new
com.sun.xml.bind.util.ListImpl(new java.util.Vector());
This looks better, but when I use the MyObject.getMyList() function,
it returns a java.util.List object. Not a java.util.Vector.
Is there anyway that I can cast it or change the function signature to
return a Vector?
Is it returning a Vector.
It is returning a java.util.List reference to the Vector object.
This is the correct way to use the Collections API.
You should never (loosely speaking) create a reference to a List, Set or Map
implementation class (such as java.util.Vector).
You *can* cast it, but chances are, you don't want you.
Or ... you think you want to, but you don't understand that you would be
writing poor code.
The fact that you are changing List implementations (from ArrayList to
Vector) is a perfect example of why you want to handle the returned List
reference transparently (to the implementation).
Perhaps this will help:
http://java.sun.com/docs/books/tutor...tro/index.html
--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software
(2003 VTR1000F)