Skip to content

Commit d0f5607

Browse files
committed
a comment added to explain the use of HashMap
to avoid misconception of contributors about using HashMap to implement a JSON object as a unordered collection by the definition
1 parent ef7a5e4 commit d0f5607

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

JSONObject.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ public String toString() {
164164
* Construct an empty JSONObject.
165165
*/
166166
public JSONObject() {
167+
// HashMap is used on purpose to ensure that elements are unordered
167168
this.map = new HashMap<String, Object>();
168169
}
169170

@@ -216,15 +217,15 @@ public JSONObject(JSONTokener x) throws JSONException {
216217
key = x.nextValue().toString();
217218
}
218219

219-
// The key is followed by ':'.
220+
// The key is followed by ':'.
220221

221222
c = x.nextClean();
222223
if (c != ':') {
223224
throw x.syntaxError("Expected a ':' after a key");
224225
}
225226
this.putOnce(key, x.nextValue());
226227

227-
// Pairs are separated by ','.
228+
// Pairs are separated by ','.
228229

229230
switch (x.nextClean()) {
230231
case ';':

0 commit comments

Comments
 (0)