简体   繁体   English

Clojure到Java Interop

[英]Clojure to Java Interop

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. 我试图让javafx2与Clojure一起工作 - 在实现一个抽象类如DoubleBinding时,我不确定在Clojure中等效的super.bind(moo)是什么。 The class I am implementing can be found here: http://docs.oracle.com/javafx/2/api/index.html . 我正在实现的类可以在这里找到: 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());
     }
 };

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. 根据代理文档代理中的方法无法访问super ...我建议您使用gen-class生成gen-class并使用它。 You can access to super 's methods if you'll expose them with :exposes-methods directive. 如果您使用:exposes-methods指令公开它们,则可以访问super的方法。 Something, like: 就像是:

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

and then call -my-bind from your constructor... 然后从你的构造函数调用-my-bind ...

Please, check documentation about class generation on Clojure's site for more details on gen-class 请查看Clojure网站上关于类生成的文档,以获取有关gen-class更多详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM