gpt4 book ai didi

Clojure 到 Java 互操作

转载 作者:行者123 更新时间:2023-12-02 15:26:15 27 4
gpt4 key购买 nike

我正在尝试让 javafx2 与 Clojure 一起使用 - 在实现像 DoubleBinding 这样的抽象类时,我不确定 Clojure 中 super.bind(moo) 的等价物是什么。我正在实现的类可以在这里找到: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());
}
};

最佳答案

根据proxy documentation ,代理中的方法无法访问 super ...我建议您使用 gen-class 生成类并使用它。您可以访问super的方法(如果您使用 :exposes-methods 公开它们)指示。一些东西,比如:

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

然后调用-my-bind从你的构造函数...

请检查documentation about class有关更多详细信息,请访问 Clojure 网站 gen-class

关于Clojure 到 Java 互操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11680854/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com