Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make memfn allow for type-hinting the method receiver.

Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
  • Loading branch information...
commit d15a1f0c3316021f5e4e225b4388c4d625c7799f 1 parent ec80266
@tsdh tsdh authored stuarthalloway committed
Showing with 6 additions and 3 deletions.
  1. +6 −3 src/clj/clojure/core.clj
View
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
Please sign in to comment.
Something went wrong with that request. Please try again.