I have two annotations. The first is used from the second:
@Target({ })
@Retention(RUNTIME)
public @interface A {
String value() default "";
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface B {
A a() default ???;
}
The logic that @B
can be used without any attributes, but, of course, it doesn't mean (by Annotation specification) that it will have nulls for its attributes.
From other side @A.value() == ""
is also OK for my logic. That means:
A a() default @A;
Isn't for me.
So, I need a case, when I can determine that @B.a()
is something like 'NO_VALUE' and it should be protected from end-user.
static final A NO_A = new A() {};
A a() default NO_A;
Doesn't help: it isn't compiled.
As a workaround I use an array
:
A[] a() default {};
And check in the annotation processor the size of a
attribute.
Are there some other options to mark a()
with something default to make it 'NULL'-like and get rid of an array style ?