[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] One target for intertype declarations

Hi Erik,

So in a nutshell you don't have two fields but two declarations of
one and the same field. (If the field had been static that would have
been a different thing)

Ok, I am getting confused now. You seem to be saying that although we have two declarations of the field there will actually only be copy of it in test2. Even though it's declared private in both test and test2?


I think the following example says otherwise:

public class test implements testinterface {
    private transient int testField;
    public test() {
	testField = 101;
	System.err.println("TEST - setting testField to 101");
    }

public int getTestField() {
System.err.println("TEST - getting testField");
return testField;
}
public int getTest1Field() { System.err.println("TEST - getting test1Field");
return testField;
}
}


public class test2 extends test implements testinterface {
    private transient int testField;
    public test2() {
	int oldTestField = testField;
	testField = 201;
	System.err.println("TEST2 - setting testField to 201 (was " + oldTestField + ")");
    }

public int getTestField() {
System.err.println("TEST2 - getting testField");
return testField;
}
public static void main(String argv[]) {
test t1 = new test();
test2 t2 = new test2();


	testinterface i1 = (testinterface) t1;
	testinterface i2 = (testinterface) t2;

	System.err.println("I1 - getTestField() = " + i1.getTestField());
	System.err.println("I2 - getTestField() = " + i2.getTestField());
	System.err.println("I2 - getTest1Field() = " + t2.getTest1Field());
    }
}
>
> public interface testinterface {
>    public abstract int getTestField();
> }

Observed output:

TEST - setting testField to 101
TEST - setting testField to 101
TEST2 - setting testField to 201 (was 0)
TEST - getting testField
I1 - getTestField() = 101
TEST2 - getting testField
I2 - getTestField() = 201
TEST - getting test1Field
I2 - getTest1Field() = 101

This indicates to me that there are two copies of testField in any instance of class test2. Do you agree or have I totally missed something?


Going back to the AspectJ implementation of pertarget, I think it's unnecessary to have two copies of the special aspect field. If the weaver sees that test2 extends test and it knows that test already includes the special aspect field, then I see no advantage in adding another field to test2.

Cheers,

Dave


Hope that helps,

Eric


- -- Eric Bodden
Chair I2 for Programming Languages and Program Analysis
RWTH Aachen University


-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0.3

iQA/AwUBQaO8h8wiFCm7RlWCEQLN2ACbBvDjTxGOY9+KeM9/e5c/yCpzKdYAni7u
hfeM9v7sDLNJOs23PRmt0gvw
=dpSs
-----END PGP SIGNATURE-----


_______________________________________________ aspectj-users mailing list aspectj-users@xxxxxxxxxxx http://dev.eclipse.org/mailman/listinfo/aspectj-users