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.

Four.java 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import java.lang.reflect.*;
  2. import java.lang.annotation.*;
  3. interface I {}
  4. class D implements I {}
  5. aspect Introduction {
  6. // ITD onto interface
  7. public String I.helloWorld( @SomeAnnotation("xyz") String who) {
  8. return "Hello " + who;
  9. }
  10. }
  11. public class Four {
  12. public static void main(String[] argv) throws Exception {
  13. Class<D> clazz = D.class;
  14. Method m = clazz.getMethod("helloWorld", String.class);
  15. Annotation[] ann = m.getAnnotations();
  16. for (int i = 0; i < m.getParameterAnnotations().length; i++) {
  17. int count = m.getParameterAnnotations()[i].length;
  18. System.out.println("Class D parameter " + i + " has " + count + " parameter annotations");
  19. }
  20. Class<I> clazzI = I.class;
  21. m = clazzI.getMethod("helloWorld", String.class);
  22. ann = m.getAnnotations();
  23. for (int i = 0; i < m.getParameterAnnotations().length; i++) {
  24. int count = m.getParameterAnnotations()[i].length;
  25. System.out.println("Interface I parameter " + i + " has " + count + " parameter annotations");
  26. }
  27. }
  28. }
  29. @Retention(RetentionPolicy.RUNTIME)
  30. @Target(ElementType.PARAMETER)
  31. @interface SomeAnnotation {
  32. String value() default "";
  33. }