clojure - How do I get the instance of the class when using gen-class -


i want use instance of class constructed via gen-class in method of class.

how access it? have insert "this" in following example:

(ns example   (:gen-class))  (defn -examplemethod []   (println (str this))) 

or impossible when using gen-class?

the first argument of clojure functions corresponding method generated gen-class takes current object method being called.

(defn -examplemethod [this]   (println (str this))) 

in addition this, have add :methods option gen-class when define method comes neither superclass nor interfaces of generated class. complete example follows.

example.clj

(ns example)  (gen-class  :name com.example.example  :methods [[examplemethod [] void]])  (defn- -examplemethod   [this]   (println (str this))) 

repl

user> (compile 'example) example  user> (.examplemethod (com.example.example.)) com.example.example@73715410 nil 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -