Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikibooksThe Free Textbook Project
Search

Clojure Programming/Examples/API Examples/Java Interaction

From Wikibooks, open books for an open world
<Clojure Programming |Examples |API Examples

memfn

[edit |edit source]
(map (memfn charAt i) ["fred" "ethel" "lucy"] [1 2 3])-> (\r \h \y)

proxy

[edit |edit source]
(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))

into-array

[edit |edit source]
user=>(into-array[123])#<Integer[][Ljava.lang.Integer;@15fadcf>user=>(into-array[12"asd"])java.lang.IllegalArgumentException:arrayelementtypemismatch(NO_SOURCE_FILE:0)user=>

double-array

[edit |edit source]
user=> (into-array (map double-array [[1.0] [2.0]])) #<double[][] [[D@1fa1bb6>

genclass

[edit |edit source]
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.) )

supers

[edit |edit source]
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}
Retrieved from "https://en.wikibooks.org/w/index.php?title=Clojure_Programming/Examples/API_Examples/Java_Interaction&oldid=3678513"
Category:

[8]ページ先頭

©2009-2025 Movatter.jp