For debugging purposes, I need to track changes to the Class attributes.
For example, consider the following class:
class Test { int myInt; String myString; ... public void setMyInt(int a) ... public void setMyString(String s) ... public printDebugLog(); } void main() { Test t = new Test(); t.setMyInt(5); t.setMyString("Hello"); t.printDebugLog(); }
I want to output something like:
myInt => 5 myString => Hello
A simple solution is to create magazines instantly. that is, adding the Log function as follows:
void Log(String s) { System.out.println(s); }
and then code the dialing functions as shown below:
void setMyString(String s) { myString = s; Log("myString => " + s); }
this requires that all the given functions be written in different ways, and I wonder if there is any solution better for such a question. For example, it might be easier (if possible) to create a SetValue function that takes two variables and sets the first attribute to the value of the second object. or something like that.
Any idea?
source share