繁体   English   中英

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

[英]How to invoke superclass' method in a Clojure gen-class method?

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

来自(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.

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

(ns my.custom.Foo
  (:gen-class
    ; ...
    :exposes-methods {fooBar parentFooBar}
    ; ...
    ))

然后实现fooBar

(defn -fooBar [this]
  (combine-appropriately (.parentFooBar this)
                         other-stuff))

1除了ns表格提供的:gen-class工具之外,还有一个gen-class宏。

这不是你的实际问题的答案,但我有一个小库让你假装InputStream是一个接口而不是一个类(所以你根本不需要gen-class)。 查看io.core.InputStream ,它可以让你io.core.InputStreamable并获得一个自定义的InputStream。 无论您需要什么样的实例字段,都可以通过reify关闭当地人。

暂无
暂无

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

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