Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling java functions from Clojure

Tags:

java

clojure

I can use (.toUpperCase "GOOD") in clojure, as "GOOD" is java string, and java string has toUpperCase method.

I also can use (java.io.File/separator) from clojure as a way of calling java functions.

But, why can't I call (java.lang/Object wait 3) or (java.lang.System/println "hi")?

  • Can't we use all the java functions from Clojure?
  • If not, is there any rule for calling them? If so, where are the reference for those functions?
like image 686
prosseek Avatar asked Aug 04 '10 14:08

prosseek


1 Answers

You can use all Java functions from Clojure. See the great page on Clojure's Java interop.

In particular, you just need to get the syntax right depending on exectly what sort of Java construct you are dealing with, e.g. executing the println method on the static member "out" from java.lang.System:

(.println (System/out) "hi")
like image 73
mikera Avatar answered Oct 06 '22 15:10

mikera