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 <mailto: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 <mailto:aspectj-users@eclipse.org>
    https://dev.eclipse.org/mailman/listinfo/aspectj-users




_______________________________________________
aspectj-users mailing list
aspectj-users@eclipse.org
https://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

Reply via email to