简体   繁体   English

当一个对象的jvm地址为0时,它是什么意思?

[英]What does it mean when the jvm address of an object is 0?

I have an object, Mutation, that I have "new"ed. 我有一个对象,突变,我有“新”编辑。 But when it prints out with toString(), the object says Mutation@0. 但是当它用toString()输出时,该对象显示Mutation @ 0。 That doesn't seem good to me. 这对我来说似乎并不好。 What might that mean? 那可能意味着什么?

That is Unsigned hexadecimal representation 那是无符号十六进制表示

As per Docs of toString() method in Object class 根据Object类中的toString()方法的Docs

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. 类Object的toString方法返回一个字符串,该字符串由对象为实例的类的名称,符号字符“@”和对象的哈希码的无符号十六进制表示组成。 In other words, this method returns a string equal to the value of: 换句话说,此方法返回一个等于值的字符串:

That zero in the sense the Hashcode not yet calculated. 那个zero在某种意义上Hashcode还没有计算出来。

Source Code: 源代码:

   public String toString() {
237        return getClass().getName() + "@" + Integer.toHexString(hashCode());
238    }

If you look at the source code of Mutation , a good chance is you'll find this in there: 如果你看一下Mutation的源代码,很有可能你会在那里找到它:

@Override public int hashCode() { 
   //TODO: implement this properly!
   return 0; 
}

The default implementation of toString() just reports this fact that hashCode returned 0. toString()的默认实现只报告hashCode返回0的事实。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM