What is the difference between proxy and reify? I have some example code:
(.listFiles (java.io.File. ".")
(proxy
[java.io.FileFilter] []
(accept [f]
(.isDirectory f))))
(.listFiles (java.io.File. ".")
(reify
java.io.FileFilter
(accept [this f]
(.isDirectory f))))
the result is same, when use proxy or reify, what is better?
Update:
I found something:
this as first parameter.From Clojure.org's overview of data types:
The method bodies of
reifyare lexical closures, and can refer to the surrounding local scope.reifydiffers fromproxyin 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.reifyis preferable toproxyin all cases where its constraints are not prohibitive.
Source: http://clojure.org/datatypes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With