Java Abstract Class and Method Overloading alternative in Haxe

144 views
Skip to first unread message

Gautam Jain

unread,
Sep 7, 2015, 4:19:00 AM9/7/15
to Haxe
I am porting jsoup from Java to Haxe, but cannot find something equivalent to abstract classes in Haxe, according to what I could find by searching the web, Haxe does not support abstract classes.
Is there some way way I can port this code without me needing to rewrite too much?

Another thing which was giving me problems was method overloading, which Haxe does not support. Is there some alternate way to get similar functionality in Haxe? Or will I have to rewrite those parts?

Juraj Kirchheim

unread,
Sep 7, 2015, 5:11:10 AM9/7/15
to haxe...@googlegroups.com
On Mon, Sep 7, 2015 at 10:19 AM, Gautam Jain <jain.g...@gmail.com> wrote:
I am porting jsoup from Java to Haxe, but cannot find something equivalent to abstract classes in Haxe, according to what I could find by searching the web, Haxe does not support abstract classes.
Is there some way way I can port this code without me needing to rewrite too much?

Why not just use classes where the constructor is private and the implementation is `throw "not implemented";`.
 
Another thing which was giving me problems was method overloading, which Haxe does not support. Is there some alternate way to get similar functionality in Haxe? Or will I have to rewrite those parts?

That depends on the nature of the overload.

In some cases, you can use abstracts, e.g.:


  abstract Emissible(String) from String to String {
    @:from static function ofChars(chars:NativeArray<Int>) return String.fromChars(chars);//whatever the function is actually called
    @:from static function ofChar(char:Int) return String.fromCharCode(char);
  }

  function emit(e:Emissible):Void {
    var str:String = e;
    //implementation goes here
  }

Best,
Juraj

Alexander Kuzmenko

unread,
Sep 7, 2015, 11:48:24 AM9/7/15
to Haxe
You can use macros to implement classic abstracts. Like this: https://gist.github.com/andyli/5011520

понедельник, 7 сентября 2015 г., 11:19:00 UTC+3 пользователь Gautam Jain написал:
Reply all
Reply to author
Forward
0 new messages