How to create a static member in clojure -


i have class(created deftype) , want make several static members deserialize on it. tried add theirs signatures in interface is'nt worked me(code below).

(definterface inmk   (serialize [])   (deserialize [string])   (print []))  (deftype nmklinear [^:volatile-mutable                     ^:volatile-mutable b                     ^:volatile-mutable x-sum                     ^:volatile-mutable y-sum                     ^:volatile-mutable xy-sum                     ^:volatile-mutable xq-sum                     ^:volatile-mutable n]     inmk   (serialize [this]     (str "{\"a\":"          " \"b\":" b          " \"x-sum\":" x-sum          " \"y-sum\":" y-sum          " \"xy-sum\":" xy-sum          " \"xq-sum\":" xq-sum          " \"n\":" n          "}"))    (deserialize [str]     (let [j (json/read-str str :key-fn keyword)]       (nmklinear.        (:a j) (:b j) (:x-sum j) (:y-sum j) (:xy-sum j) (:xq-sum j) (:n j)))) 

interfaces in java don't allow static methods defined on them; static members allowed constants (where field create assumed static , final), java language specification says, "the access modifier static pertains member interfaces". if java can't clojure's definterface can't either, of course.

static methods not polymorphic defining them on interface not useful anyway. keep things deserialize stand-alone functions instead (or otherwise different way organize this).

edit: starting java 8 can add static methods interface, of above out-of-date. (also i'm not clear whether clojure on supporting this.) seems example not want, though. if add interface method implementation same implementations of interface.


Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

how to receive file in java(servlet/jsp) -