5

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?

pauldoo
  • 18,087
  • 20
  • 94
  • 116

1 Answers1

5

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.

Michał Marczyk
  • 83,634
  • 13
  • 201
  • 212
  • Ahh yes, my mistake. I saw the docs for reify using `Object`, and naively tried to use it on JComponent. I'll try proxy. – pauldoo Dec 06 '10 at 16:12