Browse files

Make memfn allow for type-hinting the method receiver.

Signed-off-by: Stuart Halloway <>
  • Loading branch information...
1 parent ec80266 commit d15a1f0c3316021f5e4e225b4388c4d625c7799f @tsdh tsdh committed with stuarthalloway Mar 8, 2012
Showing with 6 additions and 3 deletions.
  1. +6 −3 src/clj/clojure/core.clj
9 src/clj/clojure/core.clj
@@ -3447,11 +3447,14 @@
"Expands into code that creates a fn that expects to be passed an
object and any args and calls the named instance method on the
object passing the args. Use when you want to treat a Java method as
- a first-class fn."
+ a first-class fn. name may be type-hinted with the method receiver's
+ type in order to avoid reflective calls."
{:added "1.0"}
[name & args]
- `(fn [target# ~@args]
- (. target# (~name ~@args))))
+ (let [t (with-meta (gensym "target")
+ (meta name))]
+ `(fn [~t ~@args]
+ (. ~t (~name ~@args)))))
(defmacro time
"Evaluates expr and prints the time it took. Returns the value of

0 comments on commit d15a1f0

Please sign in to comment.