Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Provide a constructor with Clojure reify

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?

like image 286
pauldoo Avatar asked Dec 06 '10 16:12

pauldoo


1 Answers

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.

like image 173
Michał Marczyk Avatar answered Nov 13 '22 16:11

Michał Marczyk