Effective Java 英文 第二版 读书笔记 Item 10:Always override toString

本文探讨了如何有效地实现toString方法以提高类的可用性。通过提供有用的信息,可以使调试过程更加直观,同时确保格式的一致性和可读性。

for example,PhoneNumber@163b91  class name+@+unsigned hexadecimal representation of hashcode.

define: a concise but informative representation that is easy for a person to read

providing a good toString implementation makes your class much more pleasant to use.

 

when practical,the toString method should return all of the interesting information contained in the object

 

whether or not you decide to specify the format,you should clearly document your intentions.

 

for example:

provide programmatic access to all of the information contained in the value returned by toString.

总体感觉:需要利用toString 来描述对象时候才重载,感觉应用机会比较少

转载于:https://www.cnblogs.com/linkarl/p/5568105.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值