I have various scripts that I call using callScript() to return a Map<Item,State> which I then pass to the restoreStates(Map<Item,State>) action to set the state of the items.
The issue is that, as far as I can see, there is no way to declare a variable of type Map<Item,State> due to the fact that Item is a reserved word in the DSL.
As @rlkoshak suggested in one of the other threads, it is possible to declare a variable of type Map<GenericItem,State> however this is not acceptable to restoreStates() since it explicitly requires Item not GenericItem.
Using the callScript() command and returning a Map<Item,State> is possible but the callScript() command actually returns an Object so I need to cast it to a Map<Item,State> in order for it to be accepted by restoreStates(), which can’t be done.
It seems very awkward for the storeStates() and restoreStates() functions use Map<Item,State> rather than Map<GenericItem,State>. There may well be a reason why it has to be like this but any ideas as to how to solve my problem would be greatly appreciated.
Thanks @rlkoshak but it doesn’t work:
Using a variable of type Map<Object, State> as the argument for restoreStates() yields the type mismatch error below: Type mismatch: cannot convert from Map<Object, State> to Map<Item, State>
I came up with the following ugly workround -
val Map<GenericItem, State> statesGeneric = callScript("myScriptName") as Map<GenericItem, State>
val states = storeStates()
states.putAll(statesGeneric)
restoreStates(states)
This is both ugly and still causes a validation issue warning in the log: Map is a raw type. References to generic type Map<K, V> should be parameterized
but I can’t see any other way to achieve this while restoreStates() relies on a type that cannot be defined in the DSL.