[英]How do I pass a Java function a String[] argument?
I have a function in Java that I would like to call from Clojure. 我有一个Java函数,我想从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. 因此,我需要从Clojure函数传递String[]
作为参数。 Passing any of the following: 通过以下任何一项:
[]
) (def args []
) [""]
) (def args [""]
) all yield an exception: No matching method found: createScript for class BlaBla..
all都会产生异常: No matching method found: createScript for class BlaBla..
I have also seen this Java interop documentation , but I am probably missing something. 我也看过这个Java互操作文档 ,但我可能遗漏了一些东西。 How do I call this method from Clojure? 如何从Clojure中调用此方法?
(.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. 有关详细信息,请参阅https://clojuredocs.org/clojure.core/into-array 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.