changing method instance variables. [message #53738] |
Sun, 19 June 2005 22:33  |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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;
> }
>
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.05952 seconds