tateisu
01/06/2020, 11:01 PMclass JsonObject : HashMap<String,Any?>() {
// <https://stackoverflow.com/questions/5525795/does-javascript-guarantee-object-property-order/38218582#38218582>
// ES2015 require keep insertion order
private val list = ArrayList<String>()
// ERROR: set override nothing
operator override fun set(key: String, value: Any?) {
super.set(key,value)
if(!list.contains(key)) list.add(key)
}
StavFX
01/06/2020, 11:05 PMset
is not a method of Map or HashMap, it’s an extension method from stdlib.
You should override put
tateisu
01/06/2020, 11:06 PMDominaezzz
01/06/2020, 11:11 PMHashMap
btw?tateisu
01/06/2020, 11:13 PMDominaezzz
01/06/2020, 11:15 PMLinkedHashMap
preserves insertion order. So you can just do class JsonObject : MutableMap<String, Any?>(linkedHashMapOf())
.tateisu
01/06/2020, 11:17 PMaoriani
01/06/2020, 11:22 PMStavFX
01/06/2020, 11:27 PMclass JsonObject : MutableMap<String, Any?> by LinkedHashMap()
But you should consider Andre’s question.Dominaezzz
01/06/2020, 11:28 PMStavFX
01/06/2020, 11:31 PMtypealias JsonObject = LinkedHashMap<String, Any?>
tateisu
01/06/2020, 11:37 PM