How to pass variables to overridden toString() method?

前端 未结 4 1829
孤独总比滥情好
孤独总比滥情好 2021-01-21 08:43

Is it possible to pass in a bool variable into an overridden toString() method, so it can conditionally print the object in different formats?

4条回答
  •  旧巷少年郎
    2021-01-21 09:27

    No. An overriding method must have the same signature as the method it's overriding. This means that it can't have any more parameters, since that would change the signature. I would just make a new method for the other format you want.

提交回复
热议问题