From 246350bbcdf88e6f473bdaaed2f30e50932c931d Mon Sep 17 00:00:00 2001 From: Tomas Tulka Date: Fri, 9 Jun 2017 09:00:17 +0200 Subject: [PATCH] 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 --- JSONObject.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/JSONObject.java b/JSONObject.java index f974430db..e4b0bfadc 100644 --- a/JSONObject.java +++ b/JSONObject.java @@ -164,7 +164,12 @@ public String toString() { * Construct an empty JSONObject. */ public JSONObject() { - // HashMap is used on purpose to ensure that elements are unordered + // HashMap is used on purpose to ensure that elements are unordered by + // the specification. + // JSON tends to be a portable transfer format to allows the container + // implementations to rearrange their items for a faster element + // retrieval based on associative access. + // Therefore, an implementation mustn't rely on the order of the item. this.map = new HashMap(); }