为什么我应该在 clojure 中使用 Reify 而不是代理? [英] Why should I use Reify instead of proxy in clojure?

查看:31
本文介绍了为什么我应该在 clojure 中使用 Reify 而不是代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我应该在 clojure 中使用 Reify 而不是代理?

Why should I use Reify instead of proxy in clojure?

推荐答案

reify 的方法体是词法闭包,可以引用周围的局部作用域.reifyproxy 的不同之处在于:

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

  • 仅支持协议或接口,没有具体的超类.
  • 方法体是结果类的真正方法,而不是外部 fns.
  • 对实例的方法调用是直接的,而不是使用地图查找.
  • 不支持方法映射中方法的动态交换.

结果是比代理更好的性能,无论是在构造还是调用上.reifyproxy 在其约束不是禁止的所有情况下更可取.

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.

来源:http://clojure.org/datatypes

这篇关于为什么我应该在 clojure 中使用 Reify 而不是代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆