I know that there is no java annotation inheritance. But is it possible to do something like that in java?
@TopAnnot({
@SubAnnot("value1"),
@SubAnnot("value2"),
@AnotherSubAnnot("value3"),
@SubAnnot("value4")
})
public void aMethod(String param) { ... }
The order of the @SubAnnot
and @AnotherSubAnnot
is important.
So, the following solution, won't have the same meaning, as I can't maintain the order of the annotations:
@TopAnnot(
subAnnot = {
@SubAnnot("value1"),
@SubAnnot("value2"),
@SubAnnot("value4")
},
annotherAnnot = {
@AnotherSubAnnot("value3")
}
)
public void aMethod(String param) { ... }
Another solution should have been the following, but it is far more complex to write and not really easy to understand:
@TopAnnot({
@MyAnnot(type=AnnotType.SubAnnot, value = "value1"),
@MyAnnot(type=AnnotType.SubAnnot, value = "value2"),
@MyAnnot(type=AnnotType.AnnotherSubAnnot, value = "value3"),
@MyAnnot(type=AnnotType.SubAnnot, value = "value3")
})
public void aMethod(String param) { ... }
Is there any easier solution?