#2478 Interop toFan with java.lang.Float

Jeremy Criquet Tue 29 Sep 2015

How come this line isn't in fan-1.0 / src / sys / java / fanx / util / FanUtil.java?

javaToFanTypes.put("java.lang.Long",       Sys.IntType);
javaToFanTypes.put("java.lang.Float",      Sys.FloatType); <--- This one
javaToFanTypes.put("java.lang.Double",     Sys.FloatType);

brian Wed 30 Sep 2015

Those are exact mappings and in Fantom sys::Float maps to java.lang.Double. The other types like java.lang.Float, Integer, etc require coercion to map to Fantom types in the Java FFI

Jeremy Criquet Sun 4 Oct 2015

Ahh, that makes sense. What about java.lang.UUID with sys::Uuid?

SlimerDude Sun 4 Oct 2015

For that Fantom provides its own UUID Implementation.

Jeremy Criquet Sun 4 Oct 2015

Yeah, I know. I just mean when a Java function returns a UUID type, it would be nice if it automatically converted to a sys::Uuid.

Similarly, it would be nice if this worked:

using [java] java.lang::UUID as JavaUuid
using [java] java.lang::Class as JavaClass
JavaUuid  someJavaUuid  := fromAJavaFunction()
Type      autoType      := someJavaUuid.typeof
JavaClass javaClass     := autoType->toClass
Type      fanType       := InterOp.toFan( javaClass )
echo( autoType )  // "sys::Uuid"
echo( javaClass ) // "[java] java.lang::UUID"
echo( fanType )   // "sys::Uuid"

SlimerDude Sun 4 Oct 2015

Hmm... looking at java.util.UUID and sys::Uuid they are both represented by 128 bytes - so adding to fanx.interop.Interop shouldn't be too tricky. Though I'd imagine there'd be complications around the automatic conversions.

brian Sun 4 Oct 2015

Yeah, I know. I just mean when a Java function returns a UUID type, it would be nice if it automatically converted to a sys::Uuid.

The general philosophy is never to auto-magically coerce between types, its much safer to be explicit in the code.

Login or Signup to reply.