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.

CantMatchOnInterfaceIntroducedToGenericClass.java 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package bug; // I used a "bug" package under the "src" source folder.
  2. public aspect CantMatchOnInterfaceIntroducedToGenericClass {
  3. public static interface Marker {}
  4. public static class NonGenericClass {
  5. public void doit(String msg) {
  6. System.out.println("doit(): msg = "+msg);
  7. }
  8. }
  9. public static class GenericClass<T> {
  10. public void doit(T t) {
  11. System.out.println("doit<T>(): t = "+t);
  12. }
  13. }
  14. declare parents: NonGenericClass implements Marker;
  15. declare parents: GenericClass implements Marker;
  16. pointcut nonGenericCall(): call (void NonGenericClass.doit(..));
  17. pointcut genericCall(): call (void GenericClass.doit(..));
  18. pointcut markerCall(): call (void Marker+.doit(..));
  19. private static int mCount = 0;
  20. before(): nonGenericCall() {
  21. System.out.println("nonGenericCall advice hit");
  22. }
  23. before(): genericCall() {
  24. System.out.println("genericCall advice hit");
  25. }
  26. before(): markerCall() {
  27. mCount++;
  28. System.out.println("markerCall advice hit");
  29. }
  30. public static void main(String args[]) {
  31. new NonGenericClass().doit("message1");
  32. new GenericClass<Integer>().doit(new Integer(2));
  33. if (mCount!=2) {
  34. throw new RuntimeException("Did not hit marker+ advice twice!");
  35. }
  36. }
  37. }