diff options
author | Alexander Kriegisch <Alexander@Kriegisch.name> | 2022-01-08 11:50:55 +0700 |
---|---|---|
committer | Alexander Kriegisch <Alexander@Kriegisch.name> | 2024-01-06 10:09:11 +0100 |
commit | d4a6906b3012fac6e4dbaca5854fc59ba0d67e47 (patch) | |
tree | c78540555837c12cfaef7f9cc95842668a3ee7f9 /docs/adk15notebook/covariance.adoc | |
parent | 9735e858af48ff0bce152ea489800a86a151b08d (diff) | |
download | aspectj-d4a6906b3012fac6e4dbaca5854fc59ba0d67e47.tar.gz aspectj-d4a6906b3012fac6e4dbaca5854fc59ba0d67e47.zip |
Rename '*GuideDB' directories to their actual HTML site target names
Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
Diffstat (limited to 'docs/adk15notebook/covariance.adoc')
-rw-r--r-- | docs/adk15notebook/covariance.adoc | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/docs/adk15notebook/covariance.adoc b/docs/adk15notebook/covariance.adoc new file mode 100644 index 000000000..2349bf52c --- /dev/null +++ b/docs/adk15notebook/covariance.adoc @@ -0,0 +1,86 @@ +== Covariance + +[[covariance-inJava5]] +=== Covariance in Java 5 + +Java 5 (and hence AspectJ 5) allows you to narrow the return type in an +overriding method. For example: + +[source, java] +.... +class A { + public A whoAreYou() {...} +} + +class B extends A { + // override A.whoAreYou *and* narrow the return type. + public B whoAreYou() {...} +} +.... + +[[covariance-and-join-point-matching]] +=== Covariant methods and Join Point matching + +The join point matching rules for `call` and `execution` pointcut +designators are extended to match against covariant methods. + +Given the classes `A` and `B` as defined in the previous section, and +the program fragment + +[source, java] +.... +A a = new A(); +B b = new B(); +a.whoAreYou(); +b.whoAreYou(); +.... + +The signatures for the call join point `a.whoAreYou()` are simply: + +[source, java] +.... +A A.whoAreYou() +.... + +The signatures for the call join point `b.whoAreYou()` are: + +[source, java] +.... +A A.whoAreYou() +B B.whoAreYou() +.... + +Following the join point matching rules given in xref:joinpointsignatures.adoc#jpsigs[Join Point Signatures]. + +`call(* whoAreYou())`:: + Matches both calls, (since each call join point has at least one + matching signature). +`call(* A.whoAreYou())`:: + Matches both calls, (since each call join point has at least one + matching signature). +`call(A whoAreYou())`:: + Matches both calls, (since each call join point has at least one + matching signature). +`call(A B.whoAreYou())`:: + Does not match anything - neither of the call join points has a + signature matched by this pattern. A lint warning is given for the + call `a.whoAreYou()` ("does not match because declaring type is `A`, if + match required use ``target(B)``"). +`call(A+ B.whoAreYou())`:: + Matches the call to `b.whoAreYou()` since the signature pattern + matches the signature `B B.whoAreYou()`. A lint warning is given for + the call `a.whoAreYou()` ("does not match because declaring type is `A`, + if match required use ``target(B)``"). +`call(B A.whoAreYou())`:: + Does not match anything since neither join point has a signature + matched by this pattern. +`call(B whoAreYou())`:: + Matches the call to `b.whoAreYou()` only. +`call(B B.whoAreYou())`:: + Matches the call to `b.whoAreYou()` only. + +The rule for signature matching at call and execution join points is +unchanged from AspectJ 1.2: a call or execution pointcut matches if the +signature pattern matches at least one of the signatures of the join +point, and if the modifiers of the method or constructor are matched by +any modifier pattern or annotation pattern that may be present. |