try using reflection...iterate through the properties in the method then
print
see example
public String toString()
{
StringBuffer buff = new StringBuffer();
Field[] fields = this.getClass().getDeclaredFields();
for (int i = 0; i < fields.length; i++)
{
try
{
buff.append(fields[i].getName())
.append("\t=>\t")
.append(fields[i].get(this))
.append("\n");
//System.out.println(fields[i].getName() + " : values: " +
// fields[i].get(this));
}
catch (IllegalAccessException ex)
{
ex.printStackTrace(System.out);
}
catch (IllegalArgumentException ex)
{
ex.printStackTrace(System.out);
}
}
return buff.toString();
}
"polilop" <fmatosic@@inet.hr> wrote in message
news:ds**********@ss405.t-com.hr...
I have a class with 50 string variables.
I need to see in my main program which ones are set to some values.
To do this i need to print them to the screen. I'm getting fed up writting
System.out.println(myObject.getThisString);
System.out.println(myObject.getThatString)
.....
As i have to do this few times.
Is there an easy way to print all the values in an object?
Thx