Community
Participate
Working Groups
/* Intertype field initialisers should be resolved in the aspect (lexical scope), for consistency with intertype method and constructor bodies. The program below compiles without warning, however, binding z to the z field of the target class. */ aspect Aspect { public int A.x = z; // error: z not visible. } class A { int z = 0; } public class ITA3 { public static void main(String[] args) { System.out.println(new A().x); } }
marked as target 1.2.1
This program is compiling as expected (ie. I believe it is correct to bind A.x to z in this case). A field initializer in Java for an instance variable is evaluated, and the assignment performed, each time an instance of the class is created (JLS 2.9.2). The initialization occurs in the context of the instance being created, so the type of 'this' is the targetType of the ITD. To put it another way, the program below is equivalent to writing: aspect Aspect { public int A.x; } class A { int z = 0; A() { x = z; } }
Agreed.
Fix released as part of AspectJ 1.2.1