Reputation: 4476
I'm creating a custom annotation named @Skip as shown below.
@Retention (RetentionPolicy.RUNTIME)
@Target ({ElementType.TYPE, ElementType.METHOD})
@Inherited
public @interface Skip {
public String comment() default "";
public String bug() default "";
}
Is it possible to set conditional default value on the comment and bug? What I'm trying to achieve is, if comment is provided, bug must be optional, if bug is provided comment is optional. I can do this check at run-time, but I want to find out if we can do it at compile time. This way, eclipse will show a compilation error if at least one of these is not provided by the developer.
Upvotes: 0
Views: 1868
Reputation: 38142
You could check these things at compilation time using an annotation processor.
Have a look at the Javadoc for a starting point.
If you package the processor in the same jar as the annotation and register the processor as a service, it will be exucted automagically when compiling an annotated class (must be in a different jar).
Upvotes: 1