I have trouble while trying to wrap up a clojure function into a Java interface. Here is the example :
(deftype ClojureDistanceMeasure [^clojure.lang.IFn f]
DistanceMeasure
(compute ^double [this ^doubles a ^doubles b] (double (f a b))))
(defn ->distance-measure
^DistanceMeasure
[^clojure.lang.IFn f]
(ClojureDistanceMeasure. f))
The compute
method from DistanceMeasure
(apache maths) is supposed to return. However, whatever type of type hinting I try (before args with ^, wrap into a hinted anonymous function), the progrom refuses to compile : mismatched return type, expected:double, had : java.lang.Object
.
Is this a known issue ? Is there a way to override this (even with Java code) ?
I even tried silly code, did not work too
(deftype ClojureDistanceMeasure [^clojure.lang.IFn f]
DistanceMeasure
(compute [this ^doubles a ^doubles b] (let [result (f a b)] (double (+ result 0.0)))))
This is strange because it works for other similar interfaces.
Thanks
This solves the problem :
(deftype ClojureDistanceMeasure [^clojure.lang.IFn f]
DistanceMeasure
(compute ^double [this a b] (f ^doubles a ^doubles b)))
Same without inner type hints : I must remove arguments hints and it works. I do not know if it is a Clojure missing part of issue tough.