[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-users] introducing constructor with args to constructor-less class
|
What are the specified semantics when an aspect introduces a
constructor with arguments to a class that has no constructors
(i.e. has only the implicit argumentless constructor)?
I tried a quick search through the APG at
http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/doc/progguide/printable.html
but couldn't find anything, but I could easily have missed
something.
I made the following experiment, using eclipse 3.0/AJDT 1.1.4.
Was expected the introducing aspect (Concern.java) would break the existing
client code (Client.java). It didn't, but the weave somehow messed with the
initial assignment (= 17) to Server.field1, which is done outside any
constructor.
-----------------------------------------------
Server.java:
public class Server {
private int field1 = 17;
public void showState() {
System.out.println("field1 is " + field1);
}
}
-----------------------------------------------
Concern.java:
public aspect Concern {
private int Server.field2 = 19;
public Server.new(int newval) {
System.out.print("Additional intertype constructor. ");
field2 = newval;
}
}
-----------------------------------------------
Client.java:
public class Client {
public static void main(String[] args) {
Server obj1 = new Server();
obj1.showState();
Server obj2 = new Server(23);
obj2.showState();
}
}
-----------------------------------------------
With the aspect weaved in, the output I got was:
-----------------------------------------------
field1 is 17
Additional intertype constructor. field1 is 0
-----------------------------------------------
So, the implicit argumentless constructor was still in place, but when
Client.java makes a Server instance through the introduced constructor the
initialization of field1 did not execute. Can this be right?
--
Miguel J. T. Pessoa Monteiro
Ph.D. student Minho University, Portugal
eMail: mpm@xxxxxxxxxxx
URL: http://gec.di.uminho.pt/mpm/
________________________________________________
Message sent using UebiMiau 2.7.8