Variant is new data type equivalent to Object type in Java - i.e. can be assigned with any value type - integer/string/map/list/…etc.. No type checking is performed and also the assignment is only one-way - anything to variant. When assigning variant to any other type or when variant’s value to be used in any statement, it has to be first cast into the proper type - e.g. integer or string. Assigning variant to variant works as expected.
You can look at variant as a container into which you put your data (at which point the data loose its type) and can be taken later, but before it can be used in CTL, the type has to be returned (cast function will be introduced by
Variant can be treated as list or map - i.e. array access can be performed through [ ] operator. For this to be successful the variant has, at the moment, contain value of type list of map. One way of doing this is to “initialize” variant with empty map or list first:
Variant data type can be used as function argument type and function return type.
The behavior of list/map implementation has been changed.
- Map - there is now difference between KEY mapped to NULL value and KEY not existing in MAP. Accessing non existing KEY now leads to a runtime error. Also there is no more magic when referencing multiple “embedded” lists or maps - empty MAP or LIST does not get automatically created any more - myvariant[“nonexistent”][“somekey”] previsously led to creation of empty MAP under “nonexistent” key first (so leve-2 map could contain new “somekey” key). Now, the “nonexistent” key has to be assigned empty MAP (using empty MAP literal) first.
- List - automatic extension of lists when assigning value to index outside of current List length is no longer supported. Using append() function is recommended now. Attempt to assign to non-existing index leads to runtime error.