0

For example, consider the following annotation.

Here both value & name attributes are mandatory.

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    public @interface TestAnnotation {
       String value();
       String name();
    }

But is it possible to throw compilation error while using this annotation, when either name or value is not specified ?

  • You need to write your own [annotation processor](https://www.javacodegeeks.com/2015/09/java-annotation-processors.html). – Seelenvirtuose Sep 22 '16 at 06:29
  • Hello Sathish Can't you write a custom logic like which will help you to check conditions separatly. @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (value == null) return true; return false; } https://softwarecave.org/2014/03/27/custom-bean-validation-constraints/ – Pradeep Sep 22 '16 at 07:01
  • Thanks @Seelenvirtuose, I was able to achieve what I expected using Java Annotation Processor & also I was able to integrate it with Maven, so that build fails with compilation error. – Satish Mahadevan Sep 23 '16 at 09:34

0 Answers0