Skip to content

Instantly share code, notes, and snippets.

@ejemba
Last active May 12, 2017 13:56
Show Gist options
  • Save ejemba/67df829d25824a261ca5c34f9a205d01 to your computer and use it in GitHub Desktop.
Save ejemba/67df829d25824a261ca5c34f9a205d01 to your computer and use it in GitHub Desktop.
// Server.java
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
@Documented
public @interface Server
{
}
// Main.java
public class Main {
@Server
Long port = 8080l;
@Server
String url = "http://localhost.local";
@OtherAnno
Long stuff;
...
// From Main class, I want the list of field with annotation annotated with @Qualifier
// Arrays.* is imported
Field m = // the current field
Optional<Annotation> findFirst = stream(m.getAnnotations())
.filter( a ->
stream( a.annotationType().getAnnotations())
.anyMatch( aa -> aa.annotationType().equals(Qualifier.class))
).findFirst();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment