Java:带注释的注释(和传递值) [英] Java: Annotated Annotations (and passing values)
问题描述
我有一个注释,其中确实包含其他几个注释,很像这里的一个:
I have a annotation that does include several other annotations, pretty much like this one here:
@Component // Spring Component
@Interface OsgiService { boolean isFactory() }
意味着所有用 @OsgiService
注释的类也应自动注释为 @Component
.哪个工作正常.
meaning that all classes annotated with @OsgiService
shall automatically also be annotated as @Component
. Which works fine.
然而,现在我想添加另一个注释,它有一个依赖于 @OsgiService
的 isFactory
参数的参数.
Now however, I'd like to add another annotation, that has a parameter which is dependent of the isFactory
parameter of @OsgiService
.
@Component // Spring Component
@Scope(isFactory() ? "prototype" : "singleton")
@Interface OsgiService { boolean isFactory() }
这不起作用.但是,由于注释的 isFactory
属性需要是一个静态值,难道不应该有这样的东西吗?
Which does not work. However, as isFactory
property of an annotation requires to be a static value, shouldn't it be possible to have something like this?
推荐答案
我认为这不可能.
您可以创建两个注解:@OsgiService
和 @OsgiServiceFactory
You can create two annotations: @OsgiService
and @OsgiServiceFactory
这篇关于Java:带注释的注释(和传递值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!