首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java: f21.Person@373ee92

Java: f21.Person@373ee92
EN

Stack Overflow用户
提问于 2012-12-06 05:56:57
回答 3查看 41关注 0票数 0

F21.个人1@373ee92

好的,f21表示包。人员分类类型。

有人能用简单的术语解释为什么后面跟着随机字符的是"@“吗?以及随机字符代表什么(在内存中的位置?)

当我执行以下操作但没有声明toString()方法时,我会收到此消息:

代码语言:javascript
复制
System.out.println(myObject);
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-12-06 05:58:12

如果不覆盖类中的toString()方法,将调用Object类的toString()。

代码语言:javascript
复制
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

代码语言:javascript
复制
 public String toString() {
   return getClass().getName() + "@" + Integer.toHexString(hashCode());
  }

因此,将同样的方法应用于21.Person@373ee92

21.Person(完全限定的类名)+@+37ee92(hasgcode的十六进制版本)

票数 3
EN

Stack Overflow用户

发布于 2012-12-06 05:58:20

它调用toString()实现,如果您还没有覆盖这个方法,那么它将调用Object的版本,该版本实现如下

代码语言:javascript
复制
  public String toString() {
    return getClass().getName() + "@" + Integer.toHexString(hashCode());
  }

它是该实例散列码的十六进制版本

票数 0
EN

Stack Overflow用户

发布于 2012-12-06 05:58:43

如果不覆盖toString()方法,则使用Object提供的方法。它执行the following

ObjecttoString方法返回一个字符串,该字符串由对象所属类的名称、符号字符@和对象哈希码的无符号十六进制表示形式组成。换句话说,此方法返回的字符串等于:

getClass().getName() + '@‘+ Integer.toHexString(hashCode())

“随机”字符是对象的散列码,以十六进制表示。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13733189

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档