I’m wondering is there a way to retrieve the type hinting associated with attributes declared with defrecord. e.g., if I have the following record definition:
(defrecord Foo [^Integer id ^String description])
I’d like to retrieve a map on Foo type that gives me the attributes and their hinted types. I know I can get a list of declared attributes through reflection:
(->> record .getDeclaredFields (remove #(java.lang.reflect.Modifier/isStatic (.getModifiers #))))
This does give me a list of declared fields, but their types are Object. I know Clojure is a dynamic language, but it’d be nice if the types are given back to me when I need them.
The type hints are not kept anywhere. You can manage this information userself by writing a wrapper macro for defrecord which keeps the type information. You could e.g. generate a build function for the record type that enriches the instance with metadata on the fields: