What is the difference between proxy and reify?
clojure
Solution
From Clojure.org's overview of data types:
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
Problem
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: - proxy no need the `this` as first parameter. - proxy support superclass. - proxy support arguments.