java -cp /path/to/the/clojure.jar clojure.main /path/to/your/code.cljjava -cp /path/to/the/clojure.jar clojure.mainproject_name.foo namespace ?refer for namespaces B and C, then call that function in any namespace where you want all those symbols to be available. Be aware that this makes it harder for people reading your source code to see where the symbols come from.#(%) work?(fn x (x)). #() always expands to include parens around the expression you give it. You might try #(vector x) instead.nth work on sets and maps?EnclosingClass$NestedClass(. Integer getName) work?(. Integer getName), it tries to find the static getName member and doesn't, because there isn't one. You can use this syntax to call a static method on Integer: (. Integer parseInt "42"). In short, if you can't say x.y() in Java you can't say (. x y) in Clojure, and you can't say Integer.getName() in Java.How do I call a Java method that takes a variable number of arguments?
The variable arguments are actually just an array:
(.method object fixed-args... (into-array type variable-args...)) |
How do I get primitive types like int?
Integer/TYPE |
gen-class, how do I specify which method to override based on type signature?Example1, the parent class/interface defines 2 methods
add(int i1, int i2) and add(long l1, long l2) |
: In clojure you'll write:
(defn -add-int-int [this i1 i2] ...) (defn -add-long-long [this l1 l2] ...) |
Example2, the method to override has no argument, eg.
print() |
. Then just append -void:
(defn -print-void [this] ...) |
Example3, case of a java array, specific syntax, eg. for overriding
read(char[] cbuf, int off, int len) |
: You'll use the the-type<> syntax:
(defn -read-char<>-off-len [this cbuf off len] ...) |
clojure.java.io/copy.