Tuesday 15 September 2015

java - ElementType.LOCAL_VARIABLE annotation type -


I want to make my own annotation to give details of some local variables. I do not have problems writing the annotation, problem To get information on the runtime, I could get some information from only the annotated methods or method criteria, but not from the local variable. Is there any way to get it?

My own comment is like this:

  Public Zero M (int a) @ my annotation (some information) int b = 5; }   

Or, as an alternative, what method is there any way to get the code, to parse it further and finally get the annotation value?

Thanks in advance.

You can not recover local variables with reflection. So through reflection, you can not retrieve an annotation on the local variable. I think such comments are used only for compiler warnings.

You can see

Local variable annotations are maintained without any class files (or runtime) Retention policy set on annotation type. See JLS 9.6.1.2.

If you do not want to retrieve the method code, you can use JavaPers ().

No comments:

Post a Comment