Hi Alex! I'm sorry that you think I don't appreciate his answer.
But actually, I do appreciate for your kind response. That's why I think I may not state my questions clear enough for people to understand clearly. It's my mistake. It seems my questions was misunderstood. I am quite familiar with Java, and that's why I know my questions are misunderstood. Could you spend some time reading my modified questions? I'd really thankful for your help! To make long story short: Q1: The class which I'll add a new constructor to: * public class Child { public String name = "John"; public Child(String desc) { // TODO Auto-generated constructor stub } } * The aspectJ code: * public aspect MyTest { public Child.new(String desc, int num) { System.out.println("Child Name:" + this.name); } }* If I instantiate the Child with the new constructor: * new Child("A child", 5)* What's the output? What I saw is: *Child Name:null* Different from what I expected. Q2: The class which I'll add a new constructor to: * public class Child extends Parent{ public String name = "John"; public Child(String desc) { } } * * public class Parent { public void init() { //.... } }* I add a new constructor for the *Child *in my aspect. * public aspect MyTest { public Child.new(String desc, int num) { super.init(); } } * Can the code be compiled? What I encountered is an thrown exception: *Exception in thread "main" java.lang.NoSuchMethodError: com.test2.Child.ajc$superDispatch$com_test2_Child$init()V at MyTest.ajc$postInterConstructor$MyTest$com_test2_Child(MyTest.aj:19) at com.test2.Child.<init>(Child.java:1) at MainProgram.main(MainProgram.java:11)* Thanks for your patience! Alexander Kriegisch-2 wrote > Hello. > > With all due respect: Ramnivas has answered the question before on SO > quite patiently. So as not to waste any more of his precious time I > recommend you to > - read his answer, > - think again, especially about Q1 and > - learn some basic Java. > > Sorry if it sounds rude, but you seem not to appreciate his answer, which > is also not very nice. > > Regards > Alexander > > > Am 15.07.2013 um 20:40 schrieb pai < > pikapai@ > >: > >> Hi! thanks for the response. >> >> But it seems you have some misunderstanding about my questions. >> >> So I made some modifications to make it clear. >> >> Thank you for the help :) >> >> >> >> I am currently applying AspectJ to our project, and I found a behavior >> which >> is a bit strange to me. >> >> *Q1:* >> I added a new constructor to my current class with inter-type >> declaration, >> and found that the class's member variable is not initialized if the new >> constructor is used to instantiate my class. >> >> For example: >> >> The class which I'll add a new constructor to: >> >> public class Child { >> >> public String name = "John"; >> >> public Child(String desc) { >> // TODO Auto-generated constructor stub >> } >> } >> >> The aspectJ code: >> >> public aspect MyTest { >> public Child.new(String desc, int num) { >> System.out.println("Child Name:" + this.name); >> } >> } >> >> If I instantiate the Child with the new constructor: >> >> new Child("A child", 5) >> >> the member variable **this.name** is not initialized as will be done with >> the original constructor. >> >> But, if I call the original constructor: >> >> new Child("A child") >> >> the member variable **this.name** will be initialized to "John" as usual >> >> The result: >> >>> Child Name:null >> >> **Is this a limitation of AspectJ? Is there anyway to resolve this >> issue?** >> >> I don't really want to add the code for member variable initialization to >> the new constructor. >> >> *Q2:* >> It seems **in the newly added constructor**, **super.method()** can not >> be >> correctly resolved. >> >> >> The class which I'll add a new constructor to: >> >> public class Child extends Parent{ >> >> public String name = "John"; >> >> public Child(String desc) { >> >> } >> } >> >> **Child** extends **Parent**. **Parent** has a method **init()** >> >> public class Parent { >> >> public void init() { >> //.... >> } >> >> } >> >> I add a new constructor for the **Child** in my aspect. >> public aspect MyTest { >> public Child.new(String desc, int num) { >> super.init(); >> } >> } >> >> The above aspect code will trigger an exception. >> >> Exception in thread "main" java.lang.NoSuchMethodError: >> com.test2.Child.ajc$superDispatch$com_test2_Child$init()V >> at >> MyTest.ajc$postInterConstructor$MyTest$com_test2_Child(MyTest.aj:19) >> at com.test2.Child. > <init> > (Child.java:1) >> at MainProgram.main(MainProgram.java:11) >> >> My workaround is to define **another method** for my class **Child**, and >> indirectly call the super.method() within that method >> >> >> For example, add a new method that calls **super.init()** for **Child** >> >> public void Child.initState() >> { >> super.init(); >> } >> >> Now, I can call initState() in the newly added constructor like below: >> >> public aspect MyTest { >> public Child.new(String desc, int num) { >> this.initState(); >> } >> } >> >> **Is this a limitation of AspectJ? Is this the only way to resolve this >> issue?** >> >> Thank you all for your time :) >> >> >> >> -- >> View this message in context: >> http://aspectj.2085585.n4.nabble.com/Behaviours-of-new-constructor-added-by-AspectJ-ITD-tp4651015p4651019.html >> Sent from the AspectJ - users mailing list archive at Nabble.com. >> _______________________________________________ >> aspectj-users mailing list >> > aspectj-users@ >> https://dev.eclipse.org/mailman/listinfo/aspectj-users > _______________________________________________ > aspectj-users mailing list > aspectj-users@ > https://dev.eclipse.org/mailman/listinfo/aspectj-users Alexander Kriegisch-2 wrote > Hello. > > With all due respect: Ramnivas has answered the question before on SO > quite patiently. So as not to waste any more of his precious time I > recommend you to > - read his answer, > - think again, especially about Q1 and > - learn some basic Java. > > Sorry if it sounds rude, but you seem not to appreciate his answer, which > is also not very nice. > > Regards > Alexander > > > Am 15.07.2013 um 20:40 schrieb pai < > pikapai@ > >: > >> Hi! thanks for the response. >> >> But it seems you have some misunderstanding about my questions. >> >> So I made some modifications to make it clear. >> >> Thank you for the help :) >> >> >> >> I am currently applying AspectJ to our project, and I found a behavior >> which >> is a bit strange to me. >> >> *Q1:* >> I added a new constructor to my current class with inter-type >> declaration, >> and found that the class's member variable is not initialized if the new >> constructor is used to instantiate my class. >> >> For example: >> >> The class which I'll add a new constructor to: >> >> public class Child { >> >> public String name = "John"; >> >> public Child(String desc) { >> // TODO Auto-generated constructor stub >> } >> } >> >> The aspectJ code: >> >> public aspect MyTest { >> public Child.new(String desc, int num) { >> System.out.println("Child Name:" + this.name); >> } >> } >> >> If I instantiate the Child with the new constructor: >> >> new Child("A child", 5) >> >> the member variable **this.name** is not initialized as will be done with >> the original constructor. >> >> But, if I call the original constructor: >> >> new Child("A child") >> >> the member variable **this.name** will be initialized to "John" as usual >> >> The result: >> >>> Child Name:null >> >> **Is this a limitation of AspectJ? Is there anyway to resolve this >> issue?** >> >> I don't really want to add the code for member variable initialization to >> the new constructor. >> >> *Q2:* >> It seems **in the newly added constructor**, **super.method()** can not >> be >> correctly resolved. >> >> >> The class which I'll add a new constructor to: >> >> public class Child extends Parent{ >> >> public String name = "John"; >> >> public Child(String desc) { >> >> } >> } >> >> **Child** extends **Parent**. **Parent** has a method **init()** >> >> public class Parent { >> >> public void init() { >> //.... >> } >> >> } >> >> I add a new constructor for the **Child** in my aspect. >> public aspect MyTest { >> public Child.new(String desc, int num) { >> super.init(); >> } >> } >> >> The above aspect code will trigger an exception. >> >> Exception in thread "main" java.lang.NoSuchMethodError: >> com.test2.Child.ajc$superDispatch$com_test2_Child$init()V >> at >> MyTest.ajc$postInterConstructor$MyTest$com_test2_Child(MyTest.aj:19) >> at com.test2.Child. > <init> > (Child.java:1) >> at MainProgram.main(MainProgram.java:11) >> >> My workaround is to define **another method** for my class **Child**, and >> indirectly call the super.method() within that method >> >> >> For example, add a new method that calls **super.init()** for **Child** >> >> public void Child.initState() >> { >> super.init(); >> } >> >> Now, I can call initState() in the newly added constructor like below: >> >> public aspect MyTest { >> public Child.new(String desc, int num) { >> this.initState(); >> } >> } >> >> **Is this a limitation of AspectJ? Is this the only way to resolve this >> issue?** >> >> Thank you all for your time :) >> >> >> >> -- >> View this message in context: >> http://aspectj.2085585.n4.nabble.com/Behaviours-of-new-constructor-added-by-AspectJ-ITD-tp4651015p4651019.html >> Sent from the AspectJ - users mailing list archive at Nabble.com. >> _______________________________________________ >> aspectj-users mailing list >> > aspectj-users@ >> https://dev.eclipse.org/mailman/listinfo/aspectj-users > _______________________________________________ > aspectj-users mailing list > aspectj-users@ > https://dev.eclipse.org/mailman/listinfo/aspectj-users -- View this message in context: http://aspectj.2085585.n4.nabble.com/Behaviours-of-new-constructor-added-by-AspectJ-ITD-tp4651015p4651021.html Sent from the AspectJ - users mailing list archive at Nabble.com. _______________________________________________ aspectj-users mailing list aspectj-users@eclipse.org https://dev.eclipse.org/mailman/listinfo/aspectj-users