When is it desired to not implement toString() in Java?

后端 未结 24 2138
心在旅途
心在旅途 2020-12-10 00:45

A lead developer on my project has taken to referring to the project\'s toString() implementations as \"pure cruft\" and is looking to remove them from the code base.

<
24条回答
  •  悲&欢浪女
    2020-12-10 01:20

    Personally, I implement them when I'm going to use objects in a JList, JTable, or other structure that uses toString() OR when I'm debugging (yes, eclipse has debug formatters but toString() is easier).

    Perhaps you can fire back that many JDK classes have toString(). Should they be removed as well? ;)

提交回复
热议问题