(defn print-methods
"For a class 'x', print the methods (ordered by their name) in
the following fashion:
<methodName>(<parameters if any>) -> <return value>"
[x]
(let [meth-seq (-> x class .getMethods seq)
ordered-seq (sort-by #(.getName %) meth-seq)
params (fn [m]
(let [ptypes (.getParameterTypes m)]
(if (= 0 (count ptypes))
""
(clojure.string/join ", "
(for [x ptypes]
(.getName x))))))]
(printf "class %s\n-----------\n" (-> x class .getName))
(doseq [m ordered-seq]
(printf "%s(%s) -> %s\n" (.getName m) (params m) (.getReturnType m)))))
The function `print-methods` is intended to be used inside a REPL. Just copy and paste it to your REPL and enjoy:
```clojure
main=> ; paste print-methods
main=> (print-methods 1)
class java.lang.Long
-----------
bitCount(long) -> int
byteValue() -> byte
compare(long, long) -> int
;...
```