Skip to content

Commit d15a1f0

Browse files
tsdhstuarthalloway
authored andcommitted
Make memfn allow for type-hinting the method receiver.
Signed-off-by: Stuart Halloway <[email protected]>
1 parent ec80266 commit d15a1f0

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/clj/clojure/core.clj

+6-3
Original file line numberDiff line numberDiff line change
@@ -3447,11 +3447,14 @@
34473447
"Expands into code that creates a fn that expects to be passed an
34483448
object and any args and calls the named instance method on the
34493449
object passing the args. Use when you want to treat a Java method as
3450-
a first-class fn."
3450+
a first-class fn. name may be type-hinted with the method receiver's
3451+
type in order to avoid reflective calls."
34513452
{:added "1.0"}
34523453
[name & args]
3453-
`(fn [target# ~@args]
3454-
(. target# (~name ~@args))))
3454+
(let [t (with-meta (gensym "target")
3455+
(meta name))]
3456+
`(fn [~t ~@args]
3457+
(. ~t (~name ~@args)))))
34553458

34563459
(defmacro time
34573460
"Evaluates expr and prints the time it took. Returns the value of

0 commit comments

Comments
 (0)