gpt4 book ai didi

java - java中toString()有什么用

转载 作者:行者123 更新时间:2023-12-03 02:28:34 25 4
gpt4 key购买 nike

Possible Duplicates:
What are the original reasons for ToString() in Java and .NET?
when to use toString() method

java中toString()的主要用途是什么

最佳答案

作为javadoc说:

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 中表示

等等

但是,建议您仅将其用于内部目的,例如日志记录和调试。

关于java - java中toString()有什么用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2887640/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com