flailing with anonymous inline object instances

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

flailing with anonymous inline object instances

Raoul Duke
say i have an interface IFoo, in java i can do something like:
someObj.methodFoobar( new IFoo() { @Override public void doFoo(
"stimpy!" ); } );

how do i do something like that in haXe syntax?
i've been looking at the docs. honest!

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: flailing with anonymous inline object instances

Franco Ponticelli
You can probably use some macro magic but my suggestion is to skip the interface altogether and use a Typedef instead:

typedef TFoo = { public function doFoo() : String; };

...

someObj.methodFoobar({ doFoo : function() return "stimpy!" });

And for such a simple case a typedef on the function is probably even better:

typedef FFoo = Void -> String;

Franco

On Wed, Dec 21, 2011 at 2:52 PM, Raoul Duke <[hidden email]> wrote:
say i have an interface IFoo, in java i can do something like:
someObj.methodFoobar( new IFoo() { @Override public void doFoo(
"stimpy!" ); } );

how do i do something like that in haXe syntax?
i've been looking at the docs. honest!

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: flailing with anonymous inline object instances

Juraj Kirchheim
In reply to this post by Raoul Duke
You could do something like that with macros in fact, but I don't see
why you would. Use a function type or anonymous type instead of IFoo.

On Wed, Dec 21, 2011 at 10:52 PM, Raoul Duke <[hidden email]> wrote:

> say i have an interface IFoo, in java i can do something like:
> someObj.methodFoobar( new IFoo() { @Override public void doFoo(
> "stimpy!" ); } );
>
> how do i do something like that in haXe syntax?
> i've been looking at the docs. honest!
>
> --
> haXe - an open source web programming language
> http://haxe.org

--
haXe - an open source web programming language
http://haxe.org
Loading...