Search for all instances of certain annotation type
Posted
by
user1064918
on Stack Overflow
See other posts from Stack Overflow
or by user1064918
Published on 2012-04-01T00:13:55Z
Indexed on
2012/04/01
5:29 UTC
Read the original article
Hit count: 154
annotations
Suppose I have this annotation
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Name
{
String value();
}
This is going to be used as follows
@Name("name1")
public static Foo foo = new Foo();
I have multiples of these across my project source files. Is there an fairly simple way to search and collect all those "foo"s that're preceded by @Name
?
In other words, I'd like to write a method that would return a Set<Foo>
containing these.
Thanks!!!
© Stack Overflow or respective owner