Provide a constructor with Clojure reify

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

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

+4
source share
1 answer

You cannot use reify to subclass and instantiate classes - it is intended only for use with protocols and interfaces. (However, you can provide an implementation of the Object methods.)

To create anonymous subclasses of arbitrary classes and / or interfaces, use proxy . All arguments of the superclass ctor proxy, if any, are included in the args vector (second argument) of the proxy form:

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

See (doc proxy) details.

+5
source

All Articles