Skip to content

Commit 246350b

Browse files
committed
comment added to explain the reason that JSON object is unordered
to avoid implementators' misconceptions and tries to reimplement the JSON object to keep the elements order
1 parent d0f5607 commit 246350b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

JSONObject.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,12 @@ public String toString() {
164164
* Construct an empty JSONObject.
165165
*/
166166
public JSONObject() {
167-
// HashMap is used on purpose to ensure that elements are unordered
167+
// HashMap is used on purpose to ensure that elements are unordered by
168+
// the specification.
169+
// JSON tends to be a portable transfer format to allows the container
170+
// implementations to rearrange their items for a faster element
171+
// retrieval based on associative access.
172+
// Therefore, an implementation mustn't rely on the order of the item.
168173
this.map = new HashMap<String, Object>();
169174
}
170175

0 commit comments

Comments
 (0)