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.

BridgeMethodExamples.aj 744B

1234567891011121314151617181920212223242526272829
  1. public aspect BridgeMethodExamples {
  2. declare warning : execution(Object SubGeneric.foo(Object)) : "no match";
  3. declare warning : execution(Object Generic.foo(Object)) : "double match";
  4. declare warning : call(Object SubGeneric.foo(Object)) : "match";
  5. void foo() {
  6. SubGeneric rawType = new SubGeneric();
  7. rawType.foo("hi"); // call to bridge method (will result in a runtime failure in this case)
  8. Object n = new Integer(5);
  9. rawType.foo(n); // call to bridge method that would succeed at runtime
  10. }
  11. }
  12. class Generic<T> {
  13. public T foo(T someObject) {
  14. return someObject;
  15. }
  16. }
  17. class SubGeneric<N extends Number> extends Generic<N> {
  18. public N foo(N someNumber) {
  19. return someNumber;
  20. }
  21. }