Book Image

haXe 2 Beginner's Guide

5 (1)
Book Image

haXe 2 Beginner's Guide

5 (1)

Overview of this book

Table of Contents (21 chapters)
haxe 2
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Parameterized Dynamic class


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.