Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

DisjunctVarBinding_2.java 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. class A {
  2. void m() {
  3. System.out.println("A");
  4. }
  5. }
  6. class B extends A {
  7. void m() {
  8. System.out.println("B");
  9. }
  10. }
  11. public class DisjunctVarBinding_2 {
  12. public static void foo(A a, A b) {
  13. a.m();
  14. b.m();
  15. }
  16. public static void main(String[] args) {
  17. A a = new A();
  18. B b = new B();
  19. foo(b,a);
  20. }
  21. }
  22. /* Example to illustrate a problem with variable
  23. binding and (||) in pointcuts. When run, this program produces
  24. java.lang.ClassCastException immediately after
  25. the call to "foo".
  26. The reason is that the instance tests inherent
  27. in the pointcut are done separately from the
  28. variable binding.
  29. Decompiled, the code produced for the relevant call
  30. to "foo" is as follows:
  31. --------------------------------------------------
  32. DisjunctVarBinding.foo(r5, r4);
  33. label_0:
  34. {
  35. if (r5 instanceof B == false)
  36. {
  37. if (r4 instanceof B == false)
  38. {
  39. break label_0;
  40. }
  41. }
  42. IfPointcut.aspectOf().ajc$afterReturning$IfPointcut$26d(r5, (B) r4);
  43. }
  44. --------------------------------------------------
  45. It should however read something like this, using the instance
  46. tests to determine the appropriate variable binding
  47. --------------------------------------------------
  48. DisjunctVarBinding.foo(r5,r4);
  49. if (r4 instanceof B)
  50. IfPointcut.aspectOf().ajc$afterReturning$IfPointcut$26d(r5, (B)r4)
  51. else if (r5 instanceof A)
  52. IfPointcut.aspectOf().ajc$afterReturning$IfPointcut$26d(r4,(B)r5)
  53. --------------------------------------------------
  54. */