#2107 Java FFI :: How to differentiate between a long and an int

SlimerDude Mon 11 Mar 2013

I have a Java class similar to this:

class Doofus {
  Doofus(long wot) { ... }
  Doofus(int ever) { ... }
}

How to I call one constructor over the other?

Int num := 99
doofus := Doofus(num)

gives an Ambiguous call <ctor>(sys::Int).

brian Mon 11 Mar 2013

There is no way in Java FFI to resolve that correctly

SlimerDude Mon 11 Mar 2013

:( Guess I'll have to make a helper Java class then...

Fantom:

using [java] com.wotever::Doofus

class DoofusHelper {
  static native Doofus doofusFromInt(Int value)
  static native Doofus doofusFromLong(Int value)
}

Java:

package fan.wotever;

public class DoofusHelperPeer {

  public static DoofusHelper make(DoofusHelper self) {
    return new DoofusHelper();
  }

  public static Doofus doofusFromInt(long value) {
    return new Doofus((int) value);
  }

  public static Doofus doofusFromLong(Long value) {
    return new Doofus(long);
  }
}

Login or Signup to reply.