Can annotations be used for code injection?

前端 未结 4 1622
南方客
南方客 2021-02-08 18:24

I realise that this might be a question that has been asked and answered, but please bear with me.

I want to know if it is possible to use annotations to inject code int

4条回答
  •  梦如初夏
    2021-02-08 18:34

    Something needs to process the annotations, so it either happens at compile time with an annotation processor or at runtime with reflection (yes I know, there are even more exotic ways of doing it at runtime).

    He most definitely is using an annotation processor, it's just that it's implicit. The javac command will search the class path for annotation processors if not explicitly set.

    Since he uses this command to compile:

    javac -cp ~/development/panno/build/hanhuy-panno.jar *.java

    We see he has modified the class path to include the hanhuy-panno.jar, which will contain the annotation processor.

    Why not just email the guy and ask if he'll give you the code?

提交回复
热议问题