This is not possible.
The Java Language Specification, section 9.6.1, states that annotation elements/members may be of the following types:
- A primitive type
String
Class
- An enum type
- An annotation type
- An array type whose component type is one of the preceding types.
This shows that an annotation may contain an array of annotations.
However, there is no subtyping among annotations. Therefore, an annotation can only contain a homogeneous array, not a heterogeneous one.
An example of a homogeneous array (which is allowed) is
@MyCustomArrayOfAnnotation({@MyCustomAnnotationType1("a"),
@MyCustomAnnotationType1("b")})
An example of a heterogeneous array (which is not allowed) is your example:
@MyCustomArrayOfAnnotation({@MyCustomAnnotationType1,
@MyCustomAnnotationType2})