Clojure Programming/Examples/API Examples/Java Interaction
Tools
General
Sister projects
In other projects
(map (memfn charAt i) ["fred" "ethel" "lucy"] [1 2 3])-> (\r \h \y)
(defn rev-vector-seq [v] (when (< 0 (count v)) (proxy [clojure.lang.ISeq] [] (seq [] this) (first [] (peek v)) (rest [] (rev-vector-seq (pop v))))))
(doto (javax.swing.JFrame.) (.addKeyListener (proxy [java.awt.event.KeyListener] [] (keyPressed [e] (println (.getKeyChar e) " key pressed")) (keyReleased [e] (println (.getKeyChar e) " key released")) (keyTyped [e] (println (.getKeyChar e) " key typed")))) (.setVisible true))
user=>(into-array[123])#<Integer[][Ljava.lang.Integer;@15fadcf>user=>(into-array[12"asd"])java.lang.IllegalArgumentException:arrayelementtypemismatch(NO_SOURCE_FILE:0)user=>
user=> (into-array (map double-array [[1.0] [2.0]])) #<double[][] [[D@1fa1bb6>
expmeth/ClassA.java: package expmeth; public class ClassA { public void hello() { System.err.println("hello from Java!"); } public void hello(int x) { System.err.println("hello from Java " + x); } }expmeth/TestMe.clj: (ns expmeth.TestMe (:gen-class :extends expmeth.ClassA :exposes-methods {hello helloSuper})) (defn -helloSuper ([this] (.hello this) (println "hello from clojure!")) ([this x] (.hello this x) (println "hello from clojure..." x))) testing: (.helloSuper (expmeth.TestMe.) 17) (.helloSuper (expmeth.TestMe.) )user=>(import[javax.swingJFrame])javax.swing.JFrameuser=>(supersJFrame)#{java.awt.Componentjava.awt.Framejava.awt.Containerjava.awt.Windowjava.awt.MenuContainerjavax.swing.RootPaneContainerjava.lang.Objectjava.awt.image.ImageObserverjava.io.Serializablejavax.swing.WindowConstantsjavax.accessibility.Accessible}