I've built a SOAP service with JAX-WS, and it returns a number of sorted results, that ar开发者_如何学Ce basically sorted in the order the customer finds aesthetically pleasing. I've got this handled no problem in my back end, and the results are coming through consistently in the right order. Now the client piece, being generated by wsimport, is using ArrayLists when it receives these results, which are not guaranteed to preserve order when iterated. Is there any way to override this? Or even better something I can do on the SOAP side in the schema that will tell any client that it needs to preserve the order?? ( cause I just KNOW I'm going to have to do a C# client for this soon )
tia!!
is using ArrayLists when it receives these results, which are not guaranteed to preserve order when iterated.
Where does this assumption come from?
The java.util.List
interface represents an ordered collection. The order of elements in the collection is essential. Any implementation of java.util.List
which did not return the correct order of the elements in the collection when iterating would be breaking the contract of the interface.
The Javadoc for the List.iterator()
method states (emphasis mine):
Returns an iterator over the elements in this list in proper sequence.
The iterator returned by ArrayList does not violate this. It returns elements to you in the same order as the underlying array.
精彩评论