You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OnOff.java 739B

123456789101112131415161718192021222324252627282930
  1. import java.lang.annotation.*;
  2. @Retention(RetentionPolicy.RUNTIME)
  3. @interface Anno {}
  4. aspect Foo {
  5. // one way round
  6. declare @field: * OnOff.field: -@Anno;
  7. declare @field: * OnOff.field: @Anno;
  8. // the other way round
  9. declare @field: * OnOff.field2: @Anno;
  10. declare @field: * OnOff.field2: -@Anno;
  11. }
  12. public class OnOff {
  13. public static int field;
  14. public int field2;
  15. public static void main(String[]argv) throws Exception {
  16. Object o = OnOff.class.getDeclaredField("field").getAnnotation(Anno.class);
  17. System.out.println("field annotated? "+(o==null?"no":"yes"));
  18. o = OnOff.class.getDeclaredField("field2").getAnnotation(Anno.class);
  19. System.out.println("field2 annotated? "+(o==null?"no":"yes"));
  20. }
  21. }