Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Munich Clojure Workshop - 04 - Java Interop

Munich Clojure Workshop - 04 - Java Interop

Copyright © 2012-2014 Clojure Workshop Team: Maximilian Karasz, Jan Stępień, Marek Kubica, Oleksandr Petrov

Commercial use of complete work or parts of work is not allowed to anyone except for Clojure Workshop Team at whole or in parts.

Licensed under Creative Commons Attribution-NonCommercial 3.0: http://creativecommons.org/licenses/by-nc/3.0/

When using complete work or parts of work, explicit attribution is required.

Clojure Workshops

October 11, 2013
Tweet

More Decks by Clojure Workshops

Other Decks in Technology

Transcript

  1. (.println (System/out) "hello") (. (. System out) println "hello") (..

    System out (println "hello")) Friday, October 11, 13
  2. (let [hashmap (HashMap.)] (.put hashmap "a" "b") (.put hashmap "x"

    "y") hashmap) (doto (HashMap.) (.put "a" "b") (.put "x" "y")) Friday, October 11, 13
  3. (let [target (reify Runnable (run [this _] (println "hello"))) thread

    (Thread. target)] (.start thread)) Friday, October 11, 13
  4. (make-array (Integer/TYPE) 5) (aset (to-array [1 2 3]) 1 5)

    (into-array [1 2 3]) Friday, October 11, 13
  5. (gen-class :name com.example.Hello :methods [[hello [String] String]]) (defn -hello [arg]

    (str "Hello, " arg)) (.hello (com.example.Hello.) "Jan") Friday, October 11, 13
  6. (gen-class :name com.example.Hello :prefix Hello :methods [[hello [String] String]]) (defn

    Hello-hello [arg] (str "Hello, " arg)) (.hello (com.example.Hello.) "Jan") Friday, October 11, 13
  7. (gen-class :name com.example.Hello :init init :constructors {[String] []}) (defn -init

    [arg] (println "Hello, " arg)) (com.example.Hello. "Jan") Friday, October 11, 13
  8. (gen-class :name com.example.Hello :init init :state state :constructors {[Seqable] []})

    (defn -init [seq] [nil seq]) (com.example.Hello. [:a :b :c]) Friday, October 11, 13
  9. (gen-class :name com.example.Hello :init init :state state :constructors {[Seqable] []})

    (defn -init [seq] [nil seq]) (com.example.Hello. [:a :b :c]) (defn -toString [this] (str (.state this))) Friday, October 11, 13
  10. (ns org.example.namespace (:gen-class)) (defn -main [arg] (println (.toUpperCase arg))) (compile

    'org.example.namespace) java org.example.namespace hello! Friday, October 11, 13