【发布时间】:2024-01-23 19:19:01
【问题描述】:
CDI 类BeanManager 有几个方法,它们接受Annotation 或Annotation... 类型的参数。例如BeanManager.getBeans(...)。
我想知道我应该如何将我的注释作为参数传递给这些方法。
我试过BeanManager.getBeans(MyBean.class, MyAnnotation.class),但它不起作用。我见过Class.isAnnotation(),但没有什么像Class.asAnnotation() 这样可以将它作为Annotation 类型检索。
BeanManager.getBeans(MyBean.class, @MyAnnotation) 都不起作用,BeanManager.getBeans(MyBean.class, (Annotation) MyAnnotation.class) 也不起作用。
如何将我的注释类检索为Annotation 类型?
【问题讨论】:
-
不清楚您要做什么。 BeanManager.getBeans(...) 返回指定类型的 bean 实例。如果您尝试自己阅读注释,则需要使用 @Hirak 描述的反射。
标签: java parameters annotations cdi bean-manager