Java - loading annotated classes

后端 未结 4 1973
生来不讨喜
生来不讨喜 2020-12-14 16:51

I know there are incredible set of tools for loading plugin classes in java, but today an idea came to my mind.

What if I have a bunch of annotated and un-annotated

4条回答
  •  死守一世寂寞
    2020-12-14 17:25

    It all depends on what kind of requirement you have for annotation.

    Like e.g. @EJB : This annotation is designed so that container will identify and do EJB Specific work which requires scanning through files and then finding such classes.

    However if your requirement is only to enable specific functionality based on annotation then you can do it using java reflection only

    e.g. @NotNull : This annotation is designed in JSR 303 to verify that Annotated element is not null. This functionality can be easily implemented at run time using reflection API

提交回复
热议问题