Monday, June 1, 2009

Method Introspection

As a Ruby hacker, I enjoy the some of the introspection features it provides. When I first started with Clojure, I missed the ability to introspect on methods easily when reaching into the Java world. Luckily, it only took a few lines of code to get what I wanted.

(defn class-methods [x]
 (let [c (if (class? x) x (class x))]
  (distinct (sort (seq 
                   (map #(.getName %1)
                    (.getMethods c)))))))

(println (let [x (new Integer 1)] (class-methods x)))


  1. Hi there! glad to drop by your page and found these very interesting and informative stuff. Thanks for sharing, keep it up!