aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorehilsdal <ehilsdal>2004-01-29 15:50:10 +0000
committerehilsdal <ehilsdal>2004-01-29 15:50:10 +0000
commitdc30f2cbc5221641aedba041010e0253c3d02d0a (patch)
tree97ebaad162974e10f5cf5ea3246d73cd1569c582 /docs
parent520ad8a1aa6073e38f99c90c35b085cba96c76ae (diff)
downloadaspectj-dc30f2cbc5221641aedba041010e0253c3d02d0a.tar.gz
aspectj-dc30f2cbc5221641aedba041010e0253c3d02d0a.zip
Resolution for Bugzilla Bug 46282
When creating obj thru intro constructor init code fails to execute
Diffstat (limited to 'docs')
-rw-r--r--docs/progGuideDB/implementation.xml49
1 files changed, 49 insertions, 0 deletions
diff --git a/docs/progGuideDB/implementation.xml b/docs/progGuideDB/implementation.xml
index fcf05583a..96939d29a 100644
--- a/docs/progGuideDB/implementation.xml
+++ b/docs/progGuideDB/implementation.xml
@@ -217,6 +217,55 @@
</sect2>
+ <sect2>
+ <title>Initializers and Inter-type Constructors</title>
+
+ <para>
+ The code for Java initializers, such as the assignment to the
+ field d in
+ </para>
+
+<programlisting><![CDATA[
+ class C {
+ double d = Math.sqrt(2);
+ }
+]]></programlisting>
+
+ <para>
+ are considered part of constructors by the time AspectJ gets ahold
+ of bytecode. That is, the assignment of d to the square root of
+ two happens <emphasis>inside</emphasis> the default constructor of
+ C.
+ </para>
+
+ <para>
+ Thus inter-type constructors will not necessarily run a target
+ type's initialization code. In particular, if the inter-type
+ constructor calls a super-constructor (as opposed to a
+ <literal>this</literal> constructor), the target type's
+ initialization code will <emphasis>not</emphasis> be run when that
+ inter-type constructor is called.
+ </para>
+
+<programlisting><![CDATA[
+ aspect A {
+ C.new(Object o) {} // implicitly calls super()
+
+ public static void main(String[] args) {
+ System.out.println((new C() ).d); // prints 1.414...
+ System.out.println((new C(null)).d); // prints 0.0
+ }
+]]></programlisting>
+
+ <para>
+ It is the job of an inter-type constructor to do all the required
+ initialization, or to delegate to a <literal>this</literal>
+ constructor if necessary.
+ </para>
+
+ </sect2>
+
+
</sect1>
</appendix>