Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure to Java Interop

Tags:

clojure

I am trying to get javafx2 working with Clojure - In implementing an abstract class such as DoubleBinding, I am unsure what the equivalent of super.bind(moo) is in Clojure. The class I am implementing can be found here: http://docs.oracle.com/javafx/2/api/index.html.

(def moo (ObservableDoubleValue. ...))
(def foo (proxy [DoubleBinding] []
            (computeValue []
               (Math/sqrt (.getValue moo)))))



final ObservableDoubleValue moo = ...;   
DoubleBinding foo = new DoubleBinding() {
     {
         super.bind(moo);
     }

     @Override
     protected double computeValue() {
         return Math.sqrt(moo.getValue());
     }
 };
like image 593
ChrisR Avatar asked Sep 06 '26 00:09

ChrisR


1 Answers

According to proxy documentation, methods in proxy has no access to super... I would recommend you to generate class using gen-class and use it. You can access to super's methods if you'll expose them with :exposes-methods directive. Something, like:

(gen-class :name MyDoubleBinding
           :extends DoubleBinding
           :exposes-methods {bind my-bind}
 ....
 )

and then call -my-bind from your constructor...

Please, check documentation about class generation on Clojure's site for more details on gen-class

like image 106
Alex Ott Avatar answered Sep 09 '26 01:09

Alex Ott



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!