문제

When using reify in Clojure, how can I provide an expression for the constructor?

Alternatively, how can I pass arguments to the base class constructor?

도움이 되었습니까?

해결책

You cannot use reify to subclass & instantiate classes -- it's only meant for use with protocols and interfaces. (You can provide implementations of methods of Object, though.)

To instantiate anonymous subclasses of arbitrary classes and/or interfaces, use proxy. All arguments to the superclass ctor of a proxy, if any, go into the args vector (the second argument) of the proxy form:

(proxy [SomeClass SomeInterface-1 ...] [ctor-arg-1 ...]
  ; method impls follow
  ...
  )

See (doc proxy) for more details.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top