Community
Participate
Working Groups
Declare a new private member to a class. Then try to access that member in an anonymous class within an introduced method -> compile error: compile: [iajc] F:\test\TestAspect.aj:40 error The field addPA is not visible [iajc] MainUI.this.addPA.setEnabled ( false ); [iajc] F:\test\TestAspect.aj:41 error The field removePA is not visible [iajc] MainUI.this.removePA.setEnabled ( true ); [iajc] MessageHolder: (2 error) [iajc] [error 0]: error at MainUI.this.addPA.setEnabled ( false ); [iajc] F:\test\TestAspect.aj:40:0 The field addPA is not visible [iajc] [error 1]: error at MainUI.this.removePA.setEnabled ( true ); [iajc] F:\test\TestAspect.aj:41:0 The field removePA is not visible See attachment for associated test case.
Created attachment 14585 [details] Testcase The included ant build script needs aspectjrt.jar and aspectjtools.jar in the same directory in order to run.
If I declare the members as public, the code compiles. BTW. the test case is just for compile time testing, not for runtime test.
Inter-type declared methods can only see members visible to the aspect in which they are declared (so whilst 'this' inside an ITDM is a reference to the target object instance, this does not imply that the member has the same access to private member fields as a regular method in the type). If you want an ITDM to be able to access private members of the target type, you have to mark the declaring aspect as priviliged.