如何在Clojure gen-class方法中调用超类'方法?

Bil*_*ill 10 clojure

我正在尝试创建一个扩展输入流Clojure的类gen-class.如果我想调用父类的方法,我该怎么做?

Mic*_*zyk 11

(doc gen-class)1开始:

:exposes-methods {super-method-name exposed-name, ...}

It is sometimes necessary to call the superclass' implementation of an
overridden method.  Those methods may be exposed and referred in 
the new method implementation by a local name.
Run Code Online (Sandbox Code Playgroud)

所以,为了能够调用父fooBar方法,你会说

(ns my.custom.Foo
  (:gen-class
    ; ...
    :exposes-methods {fooBar parentFooBar}
    ; ...
    ))
Run Code Online (Sandbox Code Playgroud)

然后执行fooBar:

(defn -fooBar [this]
  (combine-appropriately (.parentFooBar this)
                         other-stuff))
Run Code Online (Sandbox Code Playgroud)

1除了表格:gen-class提供的设施外ns,还有一个gen-class宏观.

  • 感谢您在编辑中获得答案和其他信息.增加了.在调用中是一个重要的细节. (2认同)