Don't forget that the field is public in class A...

On Fri, Sep 20, 2013 at 12:42 PM, Jozsef Hegedus <jhegedu...@gmail.com>wrote:

>  On 20.9.2013 20.39, Andy Clement wrote:
>
>  1) I have a java class A with has no fields
>
>  class A {
> }
>
>  2) I use an aspect to introduce a field called f into A
>
>  aspect X {
>    public int A.f = 42;
> }
>
>  3) I can use f in A as if f were hard coded (in the java source) into A.
>
>  new version of A:
>
>  class A {
>   public static void main(String []argv) {
>      A a = new A();
>      System.out.println(a.f);
>      a.f=100;
>       System.out.println(a.f);
>    }
> }
>
>  ajc -1.5 A.java X.java
> java A
>  42
> 100
>
>  What makes this work is that the ITD is PUBLIC (public int A.f = 42).
> You have to be compiling the system using ajc and not javac.
>
>  cheers,
> Andy
>
>
> On 20 September 2013 08:04, Jozsef Hegedus <jhegedu...@gmail.com> wrote:
>
>> Hi,
>>
>> I think it is not possible to do the following with AspectJ but maybe I
>> am wrong :
>>
>> 1) I have a java class A which has no fields.
>> 2) I use an aspect to introduce a field called f into A.
>> 3) I can use f in A as if f were hard coded (in the java source) into A.
>>
>> Is this possible ?
>> I know it is possible to something similar by providing default
>> implementations
>> for interfaces but that is not my question (interfaces can only have
>> final fields).
>>
>> Cheers,
>>
>> Jozsef
>> _______________________________________________
>> aspectj-users mailing list
>> aspectj-users@eclipse.org
>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>>
>
>
>
> _______________________________________________
> aspectj-users mailing 
> listaspectj-users@eclipse.orghttps://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>  Thank you Andy !
>
> Jozsef
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@eclipse.org
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>


-- 
mailto:matt...@matthewadams.me <matt...@matthewadams.me>
skype:matthewadams12
googletalk:matt...@matthewadams.me
http://matthewadams.me
http://www.linkedin.com/in/matthewadams
_______________________________________________
aspectj-users mailing list
aspectj-users@eclipse.org
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to