By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,613 Members | 1,890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,613 IT Pros & Developers. It's quick & easy.

XML JAXB Binding to Vector not List

P: n/a
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?
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"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)
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.