JVM Rocks

java, groovy, grails, gradle, clojure.

Clojure: List Public Methods in a Java Class

use the function below to list the public methods in a java class

list-methods function
1
2
3
4
5
(defn list-methods
  "List methods in a class"
  [c]
  (clojure.pprint/pprint
    (map #(.toString %) (.getMethods c))))

or using the threading macro

list-methods function : using threading macro
1
2
3
4
5
6
7
(defn list-methods
  "List methods in a class"
  [c]
  (->> c
    (.getMethods)
    (map #(.toString %))
    clojure.pprint/pprint))

examples

examples
1
2
3
4
5
;; methods in the String class
(list-methods String)

;; public methods in the Long class
(list-methods Long)