저는 Java 라이브러리를 clojure에 랩핑하고 있지만 가변 길이 인수를 다루는 데 문제가 있습니다. 말해,clojure에서 java 가변 길이 인수를 처리하는 방법은 무엇입니까?
TestClass.aStaticFunction(Integer... intList){/*....*/}
나는 어떻게이 기능을 clojure라고 부를 수 있을까?
저는 Java 라이브러리를 clojure에 랩핑하고 있지만 가변 길이 인수를 다루는 데 문제가 있습니다. 말해,clojure에서 java 가변 길이 인수를 처리하는 방법은 무엇입니까?
TestClass.aStaticFunction(Integer... intList){/*....*/}
나는 어떻게이 기능을 clojure라고 부를 수 있을까?
Java 가변 인자는 actually arrays이므로 Clojure에서 배열을 전달하여 vararg 함수를 호출 할 수 있습니다.
당신은 배열로 (아마도 가변 인수 함수의 Clojure에서의 다양한 사용하여)을 Clojure의 서열을 변환 할 수 있습니다 :
(TestClass/aStaticFunction (into-array Integer [(int 1),(int 2)]))
또는
(defn a-static-function-wrapper [& args]
(TestClass/aStaticFunction (into-array Integer args))
또는
배열을하고 수동으로 인덱스를 설정(TestClass/aStaticFunction (doto (make-array Integer 3)
(aset 0 first-element)
(aset 1 second-element)
(aset 2 third-element)))
Java 가변 길이 인수는 실제로 입력으로 배열을 원합니다. 예를 들어
(TestClass/aStaticFunction (into-array Integer some-sequence-of-integers))
(TestClass/aStaticFunction (to-array '(1 2 3 4 5)))
:
그래서 Clojure에의 호출은 같은 것을해야한다
(java.util.Arrays/asList (to-array '(1 2 3 4 5)))
([Clojure의 인수에서의 가변 개수 자바 인터페이스 메소드를 구현]
의 중복 가능성 http://stackoverflow.com/questions/9103777/implement-a-java-interface-method-with-a -variable-number-of-args-in-clojure) – Jeremy