Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass an Annotation as a parameter?

The CDI class BeanManager has several methods which take parameters of type Annotation or Annotation.... For example BeanManager.getBeans(...).

I would like to know how I'm supposed to pass my annotations as parameters to those methods.

I've tried BeanManager.getBeans(MyBean.class, MyAnnotation.class), but it doesn't work that way. I've seen Class.isAnnotation(), but there's nothing like Class.asAnnotation() to retrieve it as an Annotation type.

Neither BeanManager.getBeans(MyBean.class, @MyAnnotation) worked, nor did BeanManager.getBeans(MyBean.class, (Annotation) MyAnnotation.class).

How can I retrieve my annotation class as type Annotation?

like image 228
noone Avatar asked May 21 '14 11:05

noone


1 Answers

There is an example in the documentation:

beanManager.getBeans(Object.class, new AnnotationLiteral<Any>() {});

Source: 16.6. The Bean interface

like image 99
palacsint Avatar answered Sep 18 '22 19:09

palacsint