我使用 JAX-WS 构建了一个 SOAP 服务,它返回许多排序结果,这些结果基本上按照客户认为美观的顺序排序。我已经在后端处理了这个问题,并且结果始终以正确的顺序出现。现在,由 wsimport 生成的客户端片段在收到这些结果时正在使用 ArrayList,但不能保证在迭代时保留顺序。有什么办法可以覆盖这个吗?或者更好的是我可以在模式中的 SOAP 端做一些事情,告诉任何客户端它需要保留顺序? (因为我知道我很快就必须为此做一个 C# 客户端)
蒂亚!!
最佳答案
is using ArrayLists when it receives these results, which are not guaranteed to preserve order when iterated.
这个假设从何而来?
java.util.List
interface represents an ordered collection 。集合中元素的顺序至关重要。任何 java.util.List
的实现在迭代时未返回集合中元素的正确顺序都会违反接口(interface)的约定。
The Javadoc for the List.iterator()
方法状态(强调我的):
Returns an iterator over the elements in this list in proper sequence.
ArrayList 返回的迭代器并不违反这一点。它以与底层数组相同的顺序向您返回元素。
关于java - 保留 SOAP 结果的排序顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6539473/