pmf
pmf

Reputation: 7759

Clojure: invoking multiple arity functions

I have a problem invoking the multiple arity function printf on java.io.PrintWriter (specifically, System.out).

user=> (.printf System/out (into-array Object ["foo"]))
IllegalArgumentException No matching method found: printf for class java.io.PrintStream
clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:53)
user=>

Upvotes: 1

Views: 321

Answers (1)

hsestupin
hsestupin

Reputation: 1115

Your code attempts to call method printf(Object[] arg) of java.io.PrintStream class. But such method doesn't exist. Propably you want to call this one printf(String format, Object ... args) like this:

(.printf System/out "arg1: %s" (into-array Object ["foo"]))
=> #<PrintStream java.io.PrintStream@708e4544>
arg1: foo

Here #<PrintStream java.io.PrintStream@708e4544> is an object returning from printf.

Upvotes: 3

Related Questions