2
votes

The following code exhibits the semantics that I'd like to replicate on a java static method

((partial apply (fn [x y] (print x y \newline))) ["one" "two"])

one two

nil

However, when evaluated on a static method, the following exception is thrown.

((partial apply File/createTempFile) ["hello" ".txt"])

CompilerException java.lang.RuntimeException: Unable to find static field: createTempFile in class java.io.File, compiling:(NO_SOURCE_PATH:50)

Is there any way to achieve the first scenario using the static method in the second scenario?

1

1 Answers

5
votes

apply needs a clojure function (that implements iFn) so you need to wrap the static method call in an anonymous function.

user> ((partial apply #(java.io.File/createTempFile %1 %2) ["hello" ".txt"]))
#<File /tmp/hello8601033663867010647.txt>

or without the partial:

user> (apply #(java.io.File/createTempFile %1 %2) ["hello" ".txt"])
#<File /tmp/hello2555220024359994482.txt>