1

I'm trying to do something like the following:

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface AnnotationOne {
    boolean annotationTwoToggler() default false

    {
        if (annotationTwoToggler) {
            // Apply annotation AnnotationTwo to calling type
        }
    }
}

An example of how I would use this:

@AnnotationOne(true) // Implies AnnotationTwo
public class MyClass { ... }

AnnotationTwo and its implementations are in the API that I'm using, and cannot be changed. I want to cause all implementations of AnnotationTwo to trigger given a true parameter to AnnotationOne.

How can I do this?

AAM111
  • 1,178
  • 3
  • 19
  • 39
  • yes, but the if(annotationTwoToggler) part doesn't go in the annotation, it goes in the class with the code that handles the logic behind it – Stultuske Jan 17 '19 at 21:01
  • How do I do that? – AAM111 Jan 26 '19 at 16:35
  • what exactly is your annotation supposed to trigger? validation? aop code? – Stultuske Jan 28 '19 at 06:53
  • AnnotationOne should be mainly semantic, though when passed true, AnnotationTwo would tell other classes to ignore the annotated class when searching for other classes of its nature. Code for AnnotationTwo already exists. (It's part of the API) – AAM111 Jan 28 '19 at 14:53

0 Answers0