changing method instance variables. [message #588884] |
Mon, 20 June 2005 02:33 |
Oz Kologlu Messages: 5 Registered: July 2009 |
Junior Member |
|
|
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;
}
|
|
|
Powered by
FUDForum. Page generated in 0.03168 seconds