What are the shortcut to Auto-generating toString Method in Eclipse?

后端 未结 9 1296
遥遥无期
遥遥无期 2020-12-03 13:17

Is it good or bad practice auto-generating toString methods for some simple classes?

I was thinking of generating something like below where it takes th

9条回答
  •  一整个雨季
    2020-12-03 13:57

    Be clear when adding toString() as to the audience of the generated text. Some frameworks use the toString() method to generate end user visible text (e.g. certain web frameworks), whereas many people use toString() methods to generate debugging / developer information. Either way, make sure that you have enough uniqueness in the toString implementation to satisfy your requirements.

    The default JDK implementation of toString() generates developer info, so that's usually the pattern I recommend if possible, but if you are working on a project with a different idea / expectation you could wind up confused...

提交回复
热议问题