Options for creating Java classes in Clojure -


there few different ways create java classes in clojure, tradeoffs when picking between gen-class, proxy, , reify in clojure? (are there other ways create java classes haven't listed?)

my basic understanding have listed these constructs in decreasing order of power.

use gen-class when want named class or want add new methods objects create. gen-class relies on aot compilation.

when want anonymous, one-off implementation of type use reify or proxy. not rely on aot compilation. here differences:

  1. reify supports protocols or interfaces, proxy supports concrete superclasses.
  2. reify uses true class methods, proxy uses external functions.
  3. because of #2, reify uses direct method lookup, while proxy uses map method lookup.
  4. because of #3, reify not support dynamic swapping of methods, proxy does.

reify perform better proxy, should use reify when possible. use proxy when reify's constraints prohibitive.


Comments