Tutorial by Examples

You can call an instance method using the . special form: (.trim " hello ") ;;=> "hello" You can call instance methods with arguments like this: (.substring "hello" 0 2) ;;=> "he"
You can call an instance field using the .- syntax: (def p (java.awt.Point. 0 1)) (.-x p) ;;=> 0 (.-y p) ;;=> 1
You can create instance of objects in one of two ways: (java.awt.Point. 0 1) ;;=> => #object[java.awt.Point 0x3776d535 "java.awt.Point[x=0,y=1]"] Or (new java.awt.Point 0 1) ;;=> => #object[java.awt.Point 0x3776d535 "java.awt.Point[x=0,y=1]"]
You can call static methods like this: (System/currentTimeMillis) ;;=> 1469493415265 Or pass in arguments, like this: (System/setProperty "foo" "42") ;;=> nil (System/getProperty "foo") ;;=> "42"
You can call a Clojure function from Java code by looking up the function and invoking it: IFn times = Clojure.var("clojure.core", "*"); times.invoke(2, 2); This looks up the * function from the clojure.core namespace and invokes it with the arguments 2 & 2.

Page 1 of 1