I spent the morning putting in a comma and the afternoon removing it.
-- Gustave Flaubert, French realist novelist (1821-1880)
Sean Corfield wrote:Simple answer: start here http://clojure.org/compilation
Longer answer:
You need to remember that Java "functions" all have this passed as a first argument so typically when you have String foo(String greeting) { ... } in Java, you're going to have something like (defn -foo ^String [this ^String greeting] ...) in Clojure. -foo tells the Clojure compiler to preserve the function name when generating bytecode.
In your namespace declaration, you'll specify :gen-class to indicate you want the namespace compiled to a Java class.
I spent the morning putting in a comma and the afternoon removing it.
-- Gustave Flaubert, French realist novelist (1821-1880)
Sean Corfield wrote:The type hints were meant more as an illustration of where types would go if they were needed, just to show syntax. You'd only need them if you were trying to get rid of reflection warnings. Sorry, probably more confusing than helpful.
To control the actual generated signatures of methods, you might need :methods on the :gen-class directive, if you don't want default types.
I spent the morning putting in a comma and the afternoon removing it.
-- Gustave Flaubert, French realist novelist (1821-1880)
Sean Corfield wrote:No, because they do completely different things. :methods is purely about the generated method signatures (and if you specify argument types other than Object I don't expect you'll get reflection warnings from operations on the arguments within the function itself). Type hints are used anywhere that you need to eliminate a reflection warning - which is not always arguments. In fact, more often I've seen it in let forms on on actual arguments in a specific Java method call, e.g., (.someCall ^SomeType obj ^String s)