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.

Declaration1.java 856B

1234567891011121314151617181920212223242526272829303132
  1. import java.lang.annotation.*;
  2. import java.lang.reflect.*;
  3. @Retention(RetentionPolicy.RUNTIME)
  4. @interface SampleAnnotation { }
  5. interface TestInterface { }
  6. class Test implements TestInterface{}
  7. // First case: the ITD on the interface is annotated, it should make it through
  8. // to the member added to the implementor
  9. public aspect Declaration1 {
  10. // ITD directly on the implementor
  11. @SampleAnnotation
  12. public String Test.firstProperty;
  13. // ITD on the interface
  14. @SampleAnnotation
  15. public String TestInterface.secondProperty;
  16. public static void main(String[] args) {
  17. for (Field field: Test.class.getFields()) {
  18. StringBuffer sb = new StringBuffer();
  19. sb.append(field.toString());
  20. boolean b = field.isAnnotationPresent(SampleAnnotation.class);
  21. sb.append(" has annotation:").append(b);
  22. System.out.println(sb.toString());
  23. }
  24. }
  25. }