[SOLVED][HAXE] Abstract class with implements Dynamic<Dynamic> - Possible?

Hi everyone.

I’ve created a class that is a dynamic class ( implements Dynamic< Dynamic > ),
This means i can now dynamically create fields on this class’s objects.

Now I want to create an Abstract class over that dynamic class - to create some @:to and @:from methods for implicit casting.

The problem is that now an instance of the abstract class does not allow Dynamic fields creation, and of course i cant write “implements” clause on an abstract class…

Is that even possible - to transfer the dynamic field creation property of the underlying class to the abstract class?

Thanks!

Ok, Found the answer…

If you add @:forward annotation **without specifying what fields to forward **
to the class (bafore the “abstract” clause) it will transfer all fields including the dynamic feature.

Ran into this myself lately, kind of weird :confused: (but makes sense, I guess?)

1 Like

Hi,

I am porting some AS3 code and had similar issues.
Can you share a code snippet to show the proper solution?

Sure. Its pretty simple.

if this is the base class:

package;
class BaseClass implements Dynamic<Dynamic> 
{
}

This is the abstract syntax:

package;

@:forward // this will transfer the Dynamic<Dynamic > ability to this class.
abstract AbstractBaseClass(BaseClass)
{
}

OK, so to access a field in the abstract class what notation can you use?

myObj.field or myObj[“field”] ?

use myObj.field to read and write