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.

CovariantDeclaredParent.java 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * Declaring class works - see Bug below for declaring interface.
  3. */
  4. /*
  5. public class CovariantDeclaredParent {
  6. interface Result {}
  7. public class Super {
  8. public Result result() {return null;}
  9. }
  10. class Sub extends Super {
  11. public C result() { return null; }
  12. }
  13. static aspect A {
  14. declare parents: C implements Result ;
  15. }
  16. class C {}
  17. }
  18. */
  19. /**
  20. * Declaring interface on type should happen before any
  21. * covariant return types are evaluated.
  22. */
  23. class Bug {
  24. interface Result {}
  25. interface Factory {
  26. Result getInstance();
  27. }
  28. // uncomment to get more errors with default implementation
  29. // static aspect A {
  30. // // default implementation
  31. // public Result Factory.getInstance() {
  32. // throw new UnsupportedOperationException();
  33. // }
  34. // }
  35. // D is factory for B
  36. static aspect A_forB {
  37. // bug: this should work
  38. declare parents: B implements Result;
  39. // Bug: get error here wrt invalid return type
  40. public B D.getInstance() {
  41. return new B();
  42. }
  43. }
  44. static class D implements Factory {}
  45. static class B {}
  46. // to avoid the bug, declare interface directly on class
  47. // static class B implements Result {}
  48. }