annotations - How to annotate a code block in Java -


is possible annotate block of code? e.g. cycle or curly brackets? if so, how?

first.java

package an; import an.forcycle;  class first {     public static void main(string[] args) {         first f = new first();     }      public first () {          @forcycle         {   // error: illegal start of type {             int k;         }          @forcycle         (int = 0; < 5; i++) {   // similar error (illegal start...)             system.out.println(i);         }     } } 

forcycle.java

package an;  import java.lang.annotation.documented; import java.lang.annotation.elementtype; import java.lang.annotation.retention; import java.lang.annotation.retentionpolicy; import java.lang.annotation.target;  @retention(retentionpolicy.source) public @interface forcycle {} 

according http://www.javacodegeeks.com/2012/11/java-annotations-tutorial-with-custom-annotation.html

@target – indicates kinds of program element annotation type applicable. possible values type, method, constructor, field etc. if target meta-annotation not present, annotation can used on program element.

any program element (i guess) means block, doesn't it? why can't annotate block or for? missing?

thanks help

it means "any program element out of listed".

for final word on matter, 1 refers java language specification:

annotations may used modifiers in declaration, whether package, class (including enums), interface (including annotation types), field, method, formal parameter, constructor, or local variable.

annotations may used on enum constants.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -