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:
reifysupports protocols or interfaces,proxysupports concrete superclasses.reifyuses true class methods,proxyuses external functions.- because of #2,
reifyuses direct method lookup, whileproxyuses map method lookup. - because of #3,
reifynot support dynamic swapping of methods,proxydoes.
reify perform better proxy, should use reify when possible. use proxy when reify's constraints prohibitive.
Comments
Post a Comment