0

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.

1 Answer 1

1

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).

Sign up to request clarification or add additional context in comments.

2 Comments

Never heard of annotation processor. I will try to find out what they are and how to use them.
@Buddha I added some additional information to my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.