-
I have a class that looks like this: public class Foo {
private String foo;
public String getFoo() {
return this.foo;
}
public void doSomething() {
String temp = this.foo;
// ...
}
} Is there any way to modify this class so that the resulting "fake" class would act like the following? //...
public void doSomething() {
String temp = this.getFoo(); // <--- replace "this.foo" by its getter
//...
} I'm already replacing the getter, but sometimes in the source code we use "direct" access to the fields, that would not give the same value than the getter. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Yes, you are looking for MemberSubstitution. You'd replace a field read with a method invocation. |
Beta Was this translation helpful? Give feedback.
-
That's one way. You can also set Advice.OnNonDefaultValue.class and return a primitive, but I doubt it makes a performance difference. |
Beta Was this translation helpful? Give feedback.
Yes, you are looking for MemberSubstitution. You'd replace a field read with a method invocation.