Let’s say I get the script bindings like this and then insert a map:
val sbi = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE)
val mymap = mutableMapOf<String, SomeObject>(...)
sbi["_map"] = mymap
Now within a script I try to use this object:
_map["foo"].somefield
This results in: Exception: ERROR Unresolved reference: somefield
The problem is that the binding does not know about the type of the object.
There’s a workaround that proves this theory. I can do this in the script:
val map: MutableMap<String, SomeObject> get() = (bindings["_map"] as MutableMap<String, SomeObject>)
Now using “map” works fine. This feels ugly; it leaves an “unusable” object (_map) in the namespace and it feels inefficient. I was wondering if anyone knows how to initially set up the binding with types so this workaround is unnecessary.