Why should I use Reify instead of proxy in clojure?

后端 未结 2 1233
一向
一向 2020-12-29 03:26

Why should I use Reify instead of proxy in clojure?

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-29 03:47

    The method bodies of reify are lexical closures, and can refer to the surrounding local scope. reify differs from proxy in that:

    • Only protocols or interfaces are supported, no concrete superclass.
    • The method bodies are true methods of the resulting class, not external fns.
    • Invocation of methods on the instance is direct, not using map lookup.
    • No support for dynamic swapping of methods in the method map.

    The result is better performance than proxy, both in construction and invocation. reify is preferable to proxy in all cases where its constraints are not prohibitive.

    Source: http://clojure.org/datatypes

提交回复
热议问题