Can I partial a Java method invocation in Clojure?

Viewed 615

I have a method on an object.

myObject.myMethod(1)

I can invoke this in Clojure

(.myMethod myObject 1)

I can also invoke it using information from the lexical environment

(let [x 1] (.myMethod myObject x))

Can I do this with a partial? E.g.

(let [myPartial (partial .myMethod myObject)]
      (myPartial 1))

This gives me a

java.lang.RuntimeException: Unable to resolve symbol: .myMethod in this context

I'm currently making this work with an anonymous function

(let [myThing #(.myMethod myObject %)]
      (myThing 1))

But if it would be nice to use a partial in this case. Is it possible?

I'm sure the answer will be to do with binding and dispatch but I don't yet have a feeling for where during the compiling and execution the dispatch happens.

1 Answers
Related