Home » Language IDEs » AspectJ » static crosscutting & intertype member declarations: is this a bug, a feature, a bird, a plane,
static crosscutting & intertype member declarations: is this a bug, a feature, a bird, a plane, [message #55618] |
Wed, 27 July 2005 15:03 |
Michael Moser Messages: 914 Registered: July 2009 |
Senior Member |
|
|
I am having a severe problem understanding static crosscutting (cf. see
my recent append in the AspectJ-NG, but since that NG is much less
reactive I post this here):
I boiled my problen down to the following simple example:
Assume some interface definition A, e.g.:
----%<----%<----%<----
public interface A
{
int foo();
}
----%<----%<----%<----
Assume a class B that doesn't know anything about A:
----%<----%<----%<----
public class B
{
int bar = 5;
public String toString() {
return super.toString() + "[bar=" + bar + "]";
}
public static void main(String[] args) {
B b = new B();
System.out.println("b.toString()=" + b.toString());
System.out.println("b " + (b instanceof A ? "IS" : "IS NOT") + " an
instance of A");
}
}
----%<----%<----%<----
Now, we create an aspect that does a static crosscut and defines B to
also implement A plus we directly implement the necessary methods:
----%<----%<----%<----
public aspect C {
declare parents: B extends A;
// we extend the interface A to hold another field plus the method
defined in A:
public int A.foo = 2;
public int A.foo() {
return this.foo;
}
// and we override the toString()-method:
public String A.toString() {
final StringBuffer buf = new StringBuffer(super.toString());
return buf
.append("[foo=")
.append(foo)
.append("]")
.toString();
}
}
----%<----%<----%<----
Now, if I run B.main() I get:
----%<----%<----%<----
b.toString()=B@26f95321[bar=5]
b IS an instance of A
----%<----%<----%<----
So, if B now IS and instance of A (and - at least that's how I
understand this - now de facto derives from A), why is the resulting
output string not:
b.toString()=B@26f95321[foo=2][bar=5] <<< note the [foo=2] portion
i.e. why is B's super.toString() call (in its toString()-method) not
calling the introduced A.toString()???
So, apparently, even though the declare parent ... clause declares "B to
extend A" the class B is not a full or normal subclass of A.
Is this working as designed or is this a bug in the current
AspectJ-implementation or what else?
Hope, I could make myself clear.
Michael
|
|
| | |
Goto Forum:
Current Time: Fri Sep 20 07:44:34 GMT 2024
Powered by FUDForum. Page generated in 0.03852 seconds
|