O'Reilly logo

haXe 2 by Benjamin Dasnois

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action—Assigning to Dynamic variables

When you declare a variable as being Dynamic, you will be able to assign any value to it at compile time. So you can actually compile this code:

class DynamicTest
{
public static function main()
{
var dynamicVar : Dynamic;
dynamicVar = "Hello";
dynamicVar = 123;
dynamicVar = {name:"John", lastName : "Doe"};
dynamicVar = new Array<String>();
}
}

The compiler won't mind even though you are assigning values with different types to the same variable!

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required