A nicer fix is to create an overloaded method that takes a boolean value that indicates wheter you want to print less, like the following expampleCorrect terminology is overrides.
I have class A that overwrites toString()
In general, having two toString() calls is not a good idea. Fact is toString() is not a standard function call, it's automatically called in a variety of cases. So first problem is to figure out what toString() you need in those cases. In case the call might be separated, a toCompleteString() call might work. Or perhaps an if(some_static_variable) might be needed. I'm not sold on those two solutions myself.
class AObject extends Object
{
public override String toString() { return toString(false); }
public override String toString(bool printLess)
{
if (printLess)
{
return "I am AObject";
}
else
{
return "I am AObject" + super.toString();
}
}
}
This will keep the original toString functionality and on outside conditions you can choose to print less by just passing a bool to the toString function.
PS: Disclaimer: I don't know Java well enough to ensure that code will compile correctly