在clojure与Java的互操作中有个小问题,就是Java的对象是没有成员属性的这个概念的,在clojure可以使用extend-type这个宏为Java的对象添加成员属性
(extend-type java.util.Date IMatchLookup (val-at* [this k not-found] (case k :year (.getYear this) :month (.getMonth this) :date (.getDate this) :hours (.getHours this) :minutes (.getMinutes this) not-found))) (let [d (java.util.Date. 2010 10 1 12 30)] (match [d] [{:year 2009 :month a}] [:a0 a] [{:year (:or 2010 2011) :month b}] [:a1 b]));=> [:a1 10]