toString : 什么时候返回 ClassName@HexValue, String Value 与之关联 [英] toString : when does it return ClassName@HexValue, String Value associated with it
本文介绍了toString : 什么时候返回 ClassName@HexValue, String Value 与之关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
根据定义 toString()
返回返回对象的字符串表示为:
As per definition toString()
returns "Returns a string representation of the object as:
getClass().getName() + '@' + Integer.toHexString(hashCode())
但有时我可以看到即使它在我们的类中没有被覆盖,它也会返回与之关联的字符串.我的意思是 Object.toString()
返回一些字符串而不是ClassName@HexCode
".
But sometimes I could see even if it is not Overriden in our class, it returns the String associated with it. I mean Object.toString()
returns some String but not "ClassName@HexCode
".
这是什么时候发生的.请告诉我这背后的原因是什么??
When does this happen. Please let me know whats the reason behind this ??
推荐答案
只有当一个类使用覆盖(或继承覆盖)toString() 扩展另一个类时才有可能.
It's only possible if a class extends another class with overriden (or inherited overriden) toString().
这篇关于toString : 什么时候返回 ClassName@HexValue, String Value 与之关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文