Skip to main content



      Home
Home » Language IDEs » AspectJ » changing method instance variables.
changing method instance variables. [message #53738] Sun, 19 June 2005 22:33 Go to next message
Eclipse UserFriend
Originally posted by: ozkologlu.nowhere.com

Hi all,

I would like to change the instance variable of 'b' at the point indicated
'HERE' to be "new b string" _after_ returning.

If you are in Sydney CBD (in AU) a couple of free beers supplied for a
solution!

Thanks,
Oz

public class A {
String getString(B b) {
System.out.println( b.getString() ); // outputs "b string"
String s = C.getSomething( b ); // HERE: this is where i'd like
to change instance b after returning
....
System.out.println( b.getString() ); // should output "new b string"
return s;
}

// Main method
public static void main( String[] args ) {
A a = new A():
B b = new B("b string"));
System.out.println( a.getString( b )); //outputs "b string and c
string"
}

}

public class B {
String string;
public B( String string ) { this.string = string; }
public String getString() { return this.string; }
}

public class C {
public static String getSomething( B b ) { return b.getString() + " and
c string"; }
}

The aound(?) advice needs to do something like:

String around(B b) : execution ( * C.getSomething( B ) ) && target( b ){
String s = proceed( b );
if ( s.equals( "b string and c string" )) {
b = new B("new b string"); //this does not work since it only chages
the local reference
}
return s;
}
Re: changing method instance variables. [message #53769 is a reply to message #53738] Sun, 19 June 2005 23:42 Go to previous message
Eclipse UserFriend
Originally posted by: ozkologlu.nowhere.com

Sorry, should've posted this in aspectj instead
Oz

"Oz Kologlu" <ozkologlu@nowhere.com> wrote in message
news:d959ta$vb7$1@news.eclipse.org...
> Hi all,
>
> I would like to change the instance variable of 'b' at the point indicated
> 'HERE' to be "new b string" _after_ returning.
>
> If you are in Sydney CBD (in AU) a couple of free beers supplied for a
> solution!
>
> Thanks,
> Oz
>
> public class A {
> String getString(B b) {
> System.out.println( b.getString() ); // outputs "b string"
> String s = C.getSomething( b ); // HERE: this is where i'd like
> to change instance b after returning
> ....
> System.out.println( b.getString() ); // should output "new b
> string"
> return s;
> }
>
> // Main method
> public static void main( String[] args ) {
> A a = new A():
> B b = new B("b string"));
> System.out.println( a.getString( b )); //outputs "b string and c
> string"
> }
>
> }
>
> public class B {
> String string;
> public B( String string ) { this.string = string; }
> public String getString() { return this.string; }
> }
>
> public class C {
> public static String getSomething( B b ) { return b.getString() + " and
> c string"; }
> }
>
> The aound(?) advice needs to do something like:
>
> String around(B b) : execution ( * C.getSomething( B ) ) && target( b ){
> String s = proceed( b );
> if ( s.equals( "b string and c string" )) {
> b = new B("new b string"); //this does not work since it only
> chages the local reference
> }
> return s;
> }
>
>
>
Re: changing method instance variables. [message #588895 is a reply to message #53738] Sun, 19 June 2005 23:42 Go to previous message
Eclipse UserFriend
Sorry, should've posted this in aspectj instead
Oz

"Oz Kologlu" <ozkologlu@nowhere.com> wrote in message
news:d959ta$vb7$1@news.eclipse.org...
> Hi all,
>
> I would like to change the instance variable of 'b' at the point indicated
> 'HERE' to be "new b string" _after_ returning.
>
> If you are in Sydney CBD (in AU) a couple of free beers supplied for a
> solution!
>
> Thanks,
> Oz
>
> public class A {
> String getString(B b) {
> System.out.println( b.getString() ); // outputs "b string"
> String s = C.getSomething( b ); // HERE: this is where i'd like
> to change instance b after returning
> ....
> System.out.println( b.getString() ); // should output "new b
> string"
> return s;
> }
>
> // Main method
> public static void main( String[] args ) {
> A a = new A():
> B b = new B("b string"));
> System.out.println( a.getString( b )); //outputs "b string and c
> string"
> }
>
> }
>
> public class B {
> String string;
> public B( String string ) { this.string = string; }
> public String getString() { return this.string; }
> }
>
> public class C {
> public static String getSomething( B b ) { return b.getString() + " and
> c string"; }
> }
>
> The aound(?) advice needs to do something like:
>
> String around(B b) : execution ( * C.getSomething( B ) ) && target( b ){
> String s = proceed( b );
> if ( s.equals( "b string and c string" )) {
> b = new B("new b string"); //this does not work since it only
> chages the local reference
> }
> return s;
> }
>
>
>
Previous Topic:changing method instance variables.
Next Topic:AJDT development build with updated AspectJ
Goto Forum:
  


Current Time: Thu May 08 04:01:03 EDT 2025

Powered by FUDForum. Page generated in 0.05952 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top