B@61de33
这是一个toString的返回;
61de33是十六进制的hashcode。
如何通过这个计算出对象的真正首地址。
期待高手。。

解决方案 »

  1.   

    如何通过这个计算出对象的真正首地址。 这个是一个native方法,我们不需要了解这个。我们应该自己实现自己的hashCode而不是使用系统自带的
      

  2.   

    小鸟说一下意见,建议看看object类中的 equals 和 hashcode 方法
      

  3.   

    不能通过hashcode算出对象地址。
    hashcode跟地址没有任何关系,而且对象内的方法也不会知道自己的地址,更不会通过地址算hashcode
      

  4.   

    哦,我搞错了。我以为你说的是string的hashcode。
    如果是object,hashcode是地址算出来的。但是string覆盖了object的hashcode。所以他和地址毫无关系
      

  5.   

    地址信息封装了,不然和C一样可以操作指针了. 哈哈
    HashCode只是用来在MAP中保存对象方便的
      

  6.   

    有兴趣可以自己看一下:/* Called from object.c */
    JNIEXPORT jint JNICALL
    JVM_IHashCode(JNIEnv *env, jobject obj)
    {
        uint32_t tmp;
        uint32_t rot_tmp;    /* Effectively asserts that we've already called initializeObjectHash. */
        sysAssert(rand1 != 0);    /*
         * Return value is (<obj ptr> & ~7)^rand1 + (<obj ptr> rot -3)^rand2.
         * This mangles the pointer sufficiently that it should be pretty tough to
         * guess it without access to rand1 and rand2.  The mangling function
         * (due to John Rose) is an automorphism.  Thus, it's extremely
         * unlikely to reduce the quality of the hash function (in terms of
         * "bucket dispersion").  In fact, it loads the bits most likely to
         * distinguish the object (roughly, those in 0xFF8) into the
         * lowest-order bits of the hash code, and smears them around
         * by about 3.5 bit positions.
         */
        tmp = (uint32_t)DeRef(env, obj);    rot_tmp = tmp >> 3 | tmp << (8*sizeof(uint32_t)-3);
        tmp = ((tmp & ~7) ^ rand1) + (rot_tmp ^ rand2) + offsetForNull;    /* Note:  Previous two lines could be repeated to strengthen the result. */    return tmp;
        /*
         * Proof of automorphism:  Since the low-order 3 bits of the result
         * are exactly (rand1+((tmp >> 3)^rand2))&07, one can recover
         * the bits tmp&070 given rand1, rand2 and the hash.  Likewise,
         * the next three bits of the result are exactly ((tmp&070)^rand1
         * + ((tmp >> 6)^rand2))&070, so one can also recover the bits
         * tmp&0700.  This process may be repeated until all bits are
         * recovered.  The low bits tmp&7 may be treated as if they
         * were recovered from the high bits of a 35-bit hash word.
         */
    }看看hashcode是怎么根据地址算出来的。
      

  7.   

    sun的实现是地址计算出来的,由于不是强制要求,所以不保证其他jdk实现也是用地址算的。