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—Implementing a parameterized Dynamic

When implementing a parameterized Dynamic, you will get the same behavior as with a non-parameterized Dynamic except that the fields that are not declared in the class will be of the type given as a parameter.

Let's take almost the same example but with a parameterized Dynamic:

class User implements Dynamic<String>
{
public var name : String;
public var age : Int;
//...
}
//...
var u = new User(); //u is of type User
u.name = "Benjamin"; //String
u.age = 22; //Int
u.functionrole = "Author"; //String because of the type parameter

What just happened?

As you can see here, fields that are not declared in the class are of type String because we gave String as a type parameter.

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