Why should I use Reify instead of proxy in clojure?

后端 未结 2 1231
一向
一向 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

    0 讨论(0)
  • 2020-12-29 03:54

    Use reify where you would once use proxy, unless you need to override base class methods.

    0 讨论(0)
提交回复
热议问题