Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass a Java function a String[] argument?

I have a function in Java that I would like to call from Clojure. The particular prototype is the following:

public MyClass create(String aaa, File bbb, String[] args)

I therefore need to pass a String[] as a parameter, from a Clojure function. Passing any of the following:

  • (def args [])
  • (def args [""])
  • (def args ^String [])

all yield an exception: No matching method found: createScript for class BlaBla..

I have also seen this Java interop documentation, but I am probably missing something. How do I call this method from Clojure?

like image 688
nha Avatar asked Jun 07 '26 04:06

nha


1 Answers

(.create (MyClass.) "aaa" (File. "my file") (into-array ["foo" "bar" "baz"]))

Should do the trick.

See https://clojuredocs.org/clojure.core/into-array for more details.

like image 177
slipset Avatar answered Jun 09 '26 02:06

slipset



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!