psaradhi
psaradhi

Reputation: 196

find annotated methods using clojure

How do I find all deprecated (or any other annotation) methods in a java class using clojure?

(filter #(.isAnnotationPresent % java.lang.Deprecated) (.getMethods (type java.util.Date)))

returns empty list because (type java.util.Date) returns java.lang.Class. How do I get the correct class ?

Upvotes: 0

Views: 165

Answers (1)

Shlomi
Shlomi

Reputation: 4746

Just leave out the type:

(filter #(.isAnnotationPresent % java.lang.Deprecated) 
         (.getMethods java.util.Date))

now if you want to do it from string, then just do

(filter #(.isAnnotationPresent % java.lang.Deprecated) 
         (.getMethods (Class/forName "java.util.Date"))

type is used to get the type of a value, now since symbols are resolved to actual classes, the type of the symbol is a java.lang.Class

Upvotes: 2

Related Questions