【问题标题】:Is it possible to create a clojure type with a main method? (Using deftype, not gen-class)是否可以使用 main 方法创建 clojure 类型? (使用deftype,而不是gen-class)
【发布时间】:2011-08-01 01:13:49
【问题描述】:

我见过的 clojure 中定义的主要方法的例子都使用了 gen-class 和 (defn -main ...)。是否可以使用deftype定义具有可执行main方法的类?

【问题讨论】:

    标签: clojure


    【解决方案1】:

    不可能,因为deftype可以实现的接口(协议)不能有静态方法。

    【讨论】:

      【解决方案2】:

      一个 main 方法只有在你 AOT 编译它时才有意义(使用 gen-class 或类似的)。

      如果您尝试以任何其他方式定义它,则无法使用它,因为您需要先启动 clojure 编译器/环境。所以你必须通过调用其他 main() 方法来启动应用程序.....

      【讨论】:

        猜你喜欢
        • 2019-04-09
        • 1970-01-01
        • 1970-01-01
        • 2014-12-12
        • 1970-01-01
        • 2015-11-14
        • 1970-01-01
        • 1970-01-01
        • 2015-06-11
        相关资源
        最近更新 更多