[英]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.