You can parameterize the Dynamic class to slightly modify its behavior. When parameterized, every field of a Dynamic variable will be of the given type.
Let's see an example:
class DynamicTest { public static function main() { var dynamicVar : Dynamic<String>;dynamicVar = {}; dynamicVar.name = "Benjamin"; //name is a String dynamicVar.age = 12; //Won't compile since age is a String } }
In this example, dynamicVar.name
and dynamicVar.age
are of type String
, therefore, this example will fail to compile on line 7 because we are trying to assign an Int
to a String
.