F21.个人1@373ee92
好的,f21表示包。人员分类类型。
有人能用简单的术语解释为什么后面跟着随机字符的是"@“吗?以及随机字符代表什么(在内存中的位置?)
当我执行以下操作但没有声明toString()方法时,我会收到此消息:
System.out.println(myObject);发布于 2012-12-06 05:58:12
如果不覆盖类中的toString()方法,将调用Object类的toString()。
System.out.println(myObject);// this will call toString() by default.下面是来自类的toString的Implementation。
The {@code toString} method for class {@code Object} returns a string consisting of the name of the class of which the object is an instance, the at-sign character `{@code @}', and the unsigned hexadecimal representation of the hash code of the object
public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());
}因此,将同样的方法应用于21.Person@373ee92
21.Person(完全限定的类名)+@+37ee92(hasgcode的十六进制版本)
发布于 2012-12-06 05:58:20
它调用toString()实现,如果您还没有覆盖这个方法,那么它将调用Object的版本,该版本实现如下
public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());
}它是该实例散列码的十六进制版本
发布于 2012-12-06 05:58:43
如果不覆盖toString()方法,则使用Object提供的方法。它执行the following
类
Object的toString方法返回一个字符串,该字符串由对象所属类的名称、符号字符@和对象哈希码的无符号十六进制表示形式组成。换句话说,此方法返回的字符串等于:
getClass().getName() + '@‘+ Integer.toHexString(hashCode())
“随机”字符是对象的散列码,以十六进制表示。
https://stackoverflow.com/questions/13733189
复制相似问题