Skip to content

Instantly share code, notes, and snippets.

@cassc
Created February 16, 2019 03:25
Show Gist options
  • Save cassc/fb35446d5b5c1d323f2aed16ce1137dc to your computer and use it in GitHub Desktop.
Save cassc/fb35446d5b5c1d323f2aed16ce1137dc to your computer and use it in GitHub Desktop.
Call java no-arg getter in clojure
(defn invoke-get [obj ^String field]
(.. obj
(getClass)
(getDeclaredMethod (str "get" (clojure.string/capitalize field)) (into-array Class nil))
(invoke obj (into-array Class nil))))
(invoke-get (java.util.Date.) "time")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment