2012-07-27 69 views
3

我想獲得javafx2與Clojure一起工作 - 在實現一個抽象類如DoubleBinding時,我不確定superloop(moo)在Clojure中的等價物。我正在執行的課程可以在這裏找到:http://docs.oracle.com/javafx/2/api/index.htmlClojure到Java Interop

(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()); 
    } 
}; 

回答

1

proxy documentation,在代理方法有super進不去......我建議你使用gen-class生成類,並使用它。如果您使用:exposes-methods指令公開它們,您可以訪問super的方法。東西,如:

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

,然後調用從你的構造-my-bind ...

請檢查documentation about class代上Clojure的網站,詳細瞭解gen-class

+0

什麼['代理super'] (http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/proxy-super)? – ivant 2012-07-27 10:01:02

+0

好抓,我從來沒有使用它 - 我很少做這樣的互操作... – 2012-07-28 07:57:14

+0

我試圖使用代理超,但是從我已經測試和閱讀,它必須從代理的方法內部調用。我一直在測試gen-class,並且無法在post-init構造函數中調用.bindSuper,但仍然嘗試 - 由於gen-class需要在每次更改時重新編譯,所以速度很慢。 – ChrisR 2012-07-28 09:33:39