Search code examples
javaannotationsannotation-processing

Change annotation processor dynamically


Following sample is just to explain the my implementation, please have a look at and let me know if i can get any answers for this

I have created a annotation Dispenser

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Dispenser {

}

I have two classes of type dispenser above

  1. Milk Dispenser --
  2. Drink Dispenser --

    @Dispenser
    class MilkDispenser{
    
        public void releaseDrink()
    }
    
    @Dispenser
    class DrinkDispenser{
    
        public void releaseDrink()
    }
    

and i have a class DispenserProcessor extends AbstractProcessor

Everything looks fine until unless i found a better implmentation of DispenserProcessor from the client they have their own implementation I cannot copy their code so i need a way switch to that dispenserProcessor developed by the client instead of mine

Question, is there any way @MyDispenser can extend their @ClientDispenser


Solution

  • It seems like you would have to use annotation inheritance to support this, but annotation inheritance is not supported.

    More info here: Why is not possible to extend annotations in Java?