[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
[aspectj-users] around constructor execution advice
|
- From: "Andrew Eisenberg" <andrew@xxxxxxxxxxxx>
- Date: Fri, 4 Jul 2008 14:43:10 -0700
- Delivered-to: aspectj-users@eclipse.org
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:reply-to :sender:to:subject:mime-version:content-type :content-transfer-encoding:content-disposition:x-google-sender-auth; bh=h4DM63odkTfa79uxY0BIqyN4Hi+UWws7W1aMHtrxvZk=; b=pNk/Yhkls14d3ovM5SDHBAM0VW6KSsTWXY7Q67SeClR2h0o7SxyEPEBlfdVP3FomOM b9ncBKJFPxKTM7GsrX/2msqoQrLnESd7ElEiGaGBNqJ7SBHGX027q9AJlf60xjWVfTy8 ZGCum5jReIwzxmNFqbuyqG7DeS7cugpGTMW2s=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:reply-to:sender:to:subject:mime-version :content-type:content-transfer-encoding:content-disposition :x-google-sender-auth; b=nprDQZRdRtM26YJyaTG0HCqNaIYVpwglyqDASXhnxjqh9ohQizjVXiMecO9A0/kV1U EW4joHlbqdhvHb7jktNSl1e7KaKRFmCABujeySiUgm6WaDqIzdRzX0fnvHIZif1Zp+iv 9nAKwaOmqzKdINAB1dLQfL4O9AKd2LyJs+PRM=
Interesting...at first I thought that the following behavior is a bug,
but the more I think about it, I think this is the correct behavior.
The following code is producing a compile error:
public class AroundConstructor {
AroundConstructor() { }
static aspect Aspect {
AroundConstructor around() : execution(AroundConstructor.new()) {
return proceed();
}
}
}
"Incompatible return type for applying to constructor-execution(void
AroundConstructor.<init>())"
But when I change from execution to call, it compiles cleanly. I
think the issue is that this constructor may be called by a sub-class.
In this case the sub-class is expecting a type of "AroundConstructor"
or greater (ie- a super-class), but when the constructor execution is
wrapped in around advice, the proceed() call can return anythiing of
type AroundConstructor (ie- a sub-class) and hence the types would not
match if called from a sub-class.
When changed to a call PCD, the advice is triggered at the call site
(so, the compiler knows that it is not coming from a sub-class's
constructor) and there are no problems.
Just an interesting tidbit I found for a Friday afternoon...
--a