java中toString()的用法是什么? [英] what is the use of toString() in java
本文介绍了java中toString()的用法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
java中toString()的主要用途是什么
what is main use of toString() in java
推荐答案
作为 javadoc 说:
返回对象的字符串表示形式。通常,toString方法返回一个文本表示此对象的字符串。结果应该是简洁但信息丰富的表示,便于人们阅读。建议所有子类都覆盖此方法。
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.
您可以将此用于:
- 记录
- 调试
- 在UI中表示
等。
但是,建议您仅将其用于内部用途,例如记录和调试。
However, it is advisable that you use it only for internal purposes, like logging and debugging.
这篇关于java中toString()的用法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文